全局路由首位配置
作者:互联网
全局路由首位配置
const router = new Router({ //声明router
mode: 'history',
routes: [
{
path: '/',
name: 'Home',
component: Home,
meta: {
is_login: true,
}
},
{
path: '/login',
name: 'Login',
component: Login
},
]
})
router.beforeEach(
(to, from, next) => {
if (to.meta.is_login) {
if (sessionStorage.getItem('username')) {
next()
}
else {
next({name:'Login',query:{redirect:to.fullPath}})
}
} else {
next()
}
}
)
export default router
标签:name,首位,next,meta,router,Login,全局,路由,login 来源: https://blog.csdn.net/weixin_52856202/article/details/115477295