path: '/menu', name: "menulink", component: Menu, beforeEnter: (to, from, next) => {
alert("非登录状态不能进入此页面!");
next('/login');
}
//后置钩子
// router.afterEach((to, from) => {
// alert('after each ')
// })
<template>
<h1>{{name }}</h1>
</template>
<script>
export default {
data(){
return{
name:"brownwang"
}
},
beforeRouteEnter:((to, from, next) =>{
// alert("hello "+this.name);
// next();
next((vm => {
alert("hello "+vm.name);
}))
}),
beforeRouteLeave:((to, from, next) => {
if(confirm("确定离开?")==true){
next()
}else{
next(false)
}
})
}
</script>
<style scoped>
</style>