如果是使用ts跟vue3的话,要注意的官方文档的写法,不然会报错
正确的写法是:
router.beforeEach((to, from, next) => {if (window.sessionStorage.getItem('token')) {if (to.name == '/') next({ path: '/home/driveradmin' })else next()} else {next()}})
如果觉得《vue3 router.beforeEach 全局路由守卫 白屏问题 以及报错路由无效》对你有帮助,请点赞、收藏,并留下你的观点哦!