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

//使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
  document.title = `${to.meta.title}`;
  const userName = localStorage.getItem('userName');
  if (!userName && to.path !== '/login') {
    next('/login');
  } else if (to.meta.permission) {
    userName === 'admin' ? next() : next('/404');
  } else {
    next();
  }
});

Guess you like

Origin blog.csdn.net/weixin_43853746/article/details/121773638