to 准备跳转到哪个页面
from 从哪个页面中离开
next 函数
全局守卫
router.beforeEach((to,from,next) => {
if(to.path == '/login' || to.path == '/register'){
next();
}else{
alert('先登录')
next('/login')
}
})
组件守卫
data () {
return{
name: 'zuo'
}
}
beforeRouteEnter:(to, from, next) => {
next(vm => {
alert("123" + name)
})
}
beforeRouteEnter:(to, from, next) => {
if(confirm("确认离开吗")){
next();
}else{
next(false)
}
}