const PrivateRoute = ({ component: Component, ...rest }) => (
<Route
{...rest}
render={(props) =>
getToken() !== null ? (
<Component {...props} />
) : (
<Redirect
to={{
pathname: '/signin',
state: { from: props.location }
}}
/>
)}
/>
);
const Root = () => (
<Router>
<React.Fragment>
<Navbar />
<Switch>
<Route component={...} path='/...' /> // public
<PrivateRoute component={...} path='/...' /> // private
</Switch>
</React.Fragment>
</Router>
);
ReactDOM.render(<Root />, document.getElementById('root'));
registerServiceWorker();
<Route
{...rest}
render={(props) =>
getToken() !== null ? (
<Component {...props} />
) : (
<Redirect
to={{
pathname: '/signin',
state: { from: props.location }
}}
/>
)}
/>
);
const Root = () => (
<Router>
<React.Fragment>
<Navbar />
<Switch>
<Route component={...} path='/...' /> // public
<PrivateRoute component={...} path='/...' /> // private
</Switch>
</React.Fragment>
</Router>
);
ReactDOM.render(<Root />, document.getElementById('root'));
registerServiceWorker();