路由守衛
全局
router.beforeEach((to, from, next) => {})
router.afterEach((to, from, next) => {})
組件內守衛
beforeRouteEnter((to, from, next) => {})
beforeRouteUpdate((to, from, next) => {})
beforeRouteLeave((to, from, next) => {})
路由獨享
beforeEnter((to, from, next) => {})
參數詳解
參數 | 描述 |
---|---|
to | 跳轉到哪個路由對象 |
from | 要離開的路由對象 |
next | 一個方法,可以接收參數。這個方法必須調用,不使用無法跳轉 |
next()
:要to過去next(false)
:可以不通過,中斷跳轉next('/')
:不讓過,可以去另一個地方