I have an application where I manage a cookie in the local storage. When I save a react-cookie
cookie, I set an expiration, where it would expire after 30 minutes.
So if the user idled for over 30 minutes, and tries to use the application again, it would check to see if the cookie expired or not, and if it did, the cookie would be removed, and would navigate the user back to the home page (.../#/
), like so:
const token = cookie.load('token');
if(token == undefined) {
cookie.remove('token', {path: '/'})
window.location.href = '.../#/';
}
Currently, after idling for over 30 min, the cookie expires and gets removed, and the user is navigated to the .../#/
url via window.location.href
and the actual url changes, then it just shows a blank page and the component (Home) that lies in the .../#/
via React Router route:
<Route
component={Home}
path='/'
/>
is not showing up. How come?
When I log a user out, I call the same, like so,
cookie.remove('token', {path: '/'})
window.location.href = '.../#/';
and navigates to Home
route fine and it shows up.
Will be sure to accept answer and vote up. Thank you