完整的導航解析流程
- 導航被觸發(fā)。
- 在失活的組件里調用離開守衛(wèi)晨汹。
beforeRouteLeave (to, from, next)
- 調用全局的
beforeEach(to,from,next)
守衛(wèi)。 - 在重用的組件里調用
beforeRouteUpdate(to,from,next)
守衛(wèi) (2.2+)剥扣。 - 在路由配置里調用
beforeEnter(to,from,next)
守衛(wèi)铝穷。 - 解析異步路由組件。
- 在被激活的組件里調用
beforeRouteEnter(to,from,next)
曙聂。 - 調用全局的
beforeResolve()
守衛(wèi) (2.5+)。 - 導航被確認刽锤。
- 調用全局的
afterEach(to,from)
鉤子朦佩。 - 觸發(fā) DOM 更新。
- 用創(chuàng)建好的實例調用
beforeRouteEnter(to,from,next)
守衛(wèi)中傳給next
的回調函數(shù)语稠。
router.beforeEach((to, from, next) => {
// 我們可以從 to 獲取路由元信息弄砍。
})
有next()參數(shù)的記得調用next(),將請求繼續(xù)往下執(zhí)行音婶。