[Front-end] The permission jump of router.beforeEach navigation guard

//Use the hook function to perform permission jump on the route 
router.beforeEach( ( to, from , next ) => {
   document .title = {{EJS0}} ;
   const userName = localStorage.getItem( 'userName' );
   if (!userName && to.path !== '/login' ) {
    next('/login');
  } else if (to.meta.permission) {
    userName === 'admin' ? next() : next('/404');
  } else {
    next();
  }
});

Leave a Comment

Your email address will not be published. Required fields are marked *