I create PrivateRoute
route component to check User Logged in
After logged in, I have problem when refresh page (/dashboard).
It can’t get current user
immedaitly
const PrivateRoute = ({ children, ...rest }) => {
const currentUser = useTracker(() => Meteor.user(), [])
return (
<Route
{...rest}
render={({ location }) =>
currentUser ? (
children
) : (
<Redirect
to={{
pathname: '/login',
state: { from: location }
}}
/>
)
}
/>
)
}
------------
// Routes
<Route exact path="/">
<Home />
</Route>
<Route exact path="/login">
<Login />
</Route>
<Route exact path="/register">
<Register />
</Route>
..................
<PrivateRoute exact path="/dashboard">
<Dashboard />
</PrivateRoute>
Please help me…