全局路由首位配置
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