能夠在路由裏面設置須要登陸的界面,判斷下沒有登陸就跳轉到登陸界面,登陸了就不用登陸,這裏用的是一個存儲的session
router.beforeEach((to, from, next) => {
if(to.matched.some( m => m.meta.auth)){
if(sessionStorage.getItem('isLogin')){
next()
}else{
next({path:'/login',query:{url: to.fullPath} })
}
}else{
next();
}
})this
這裏是判斷是否登陸url
this.$router.push(this.$router.currentRoute.query.url)這裏的代碼能夠直接跳轉到須要登陸的界面router