方法1:侦听器
# 写在 App.vue 里
export default {
watch: {
# 侦听 路由信息对象/地址栏对象 的变化
'$route' (newV) {
console.log(newV.params)
}
}
}
方法2:updated 钩子函数
# 写在 App.vue 里
export default {
# 使用 updated 钩子函数
updated () {
console.log(this.$route.params)
}
}
方法3:导航守卫
# 写在 new VueRouter(...) 后面
# to 要去哪
# from 从哪来
# to 和 from 都是路由信息对象/地址栏信息对象
# next() 放行函数,等价于 this.$router.push()
# next() 表示放行
# next('/路径') 强制拦截到指定路径去
router.beforeEach( (to, from, next) => {
...
})
End-------------