In my web application with “browserHistory” enabled, the “beforeEnter” option is only executed while navigating between routes. I would like that, when reloading the page from any route, the “beforeEnter” is executed to check if the user is authenticated and redirect him to the login route, but this is not happening.
What am I doing wrong?
Here is my example code:
function checkAuth({ resolve, reject }) {
const token = localStorage.getItem('@token');
if (!token) this.navigate('/sign-in');
if (!token) return reject();
return resolve();
}
const routes = [
{
path: '/',
component: PageHome,
beforeEnter: checkAuth,
},
{
path: '/city',
component: PageCity,
beforeEnter: checkAuth,
},
{
path: '/place',
component: PagePlace,
beforeEnter: checkAuth,
},
{
path: '/sign-in',
component: PageSignIn,
},
{
path: '(.*)',
component: Page404,
},
];