I am completely stuck when integrating PrivateRoute
HOC in my react.js project.
Here is my route file
import React, { Component } from "react";
import { Route, Redirect, Switch, BrowserRouter as Router } from 'react-router-dom';
import Dashboard from "../view/Dashboard/Dashboard";
import Login from "../view/Login/Login";
import Admin from "../view/UserManagement/Admin";
import cookie from 'react-cookies'
const PrivateRoute = ({ component, ...rest }) => {
const isAuthed = cookie.load('token')
console.log(isAuthed, 'dddddddddddddddddddd')
return (
<Route {...rest} exact
render = {(props) => (
isAuthed ? (
<div>
{React.createElement(component, props)}
</div>
) :
(
<Redirect
to={{
pathname: '/login',
state: { from: props.location }
}}
/>
)
)}
/>
)
}
class MainPanel extends Component {
render() {
return (
<div style={{ direction: direction }}>
<Router>
<Switch>
<Route path="/login" component={Login}/>
<PrivateRoute path="/" component={Dashboard} />
<PrivateRoute path="/AdminManagement" component={Admin} />
</Switch>
</Router>
</div>
)
}
}
export default withNamespaces('common') (MainPanel);
I am totally break my head with this but didn't get rid out of that issue. Why my console inside the PrivateRoute
doesn't show the values
Is there any issue with the react and react-router-dom versions
Thank you in advance!!!