There is one need for url authentication:
import React from "react";
import { connect } from "react-redux";
import { Switch, Route, Redirect } from "react-router-dom";
...
const IndexRouter = ({ loggedIn }) => (
<Switch>
<Route
path="/"
render={() => (loggedIn ? <Redirect to="/dashboard" /> : <Login />)}
/>
<Route exact path="/dashboard" component={DashboardRouter} />
<Route exact path="/stock" component={StockRouter} />
</Switch>
);
export default connect(
state => ({
loggedIn: state.persist.loggedIn
}),
{}
)(IndexRouter);
The code means if I have not logged in, all of url are required from client will redirect to Login
component. Other than that it will route to DashboardRouter
.
The StockRouter
is another route related with DashboardRouter
.
The problem is that if I logged in. All the unspecific url (except /dashboard
, /stock
) I manually typed showing the /dashboard
url without anything. The specific url such as /stock
can show the component StockRouter
directly.