Cannot access ‘router‘ before initialization
生活随笔
收集整理的這篇文章主要介紹了
Cannot access ‘router‘ before initialization
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在全局前置守衛配置中,要將配置信息放在創建路由對象后面使用,否則就會報錯
// 錯誤代碼 const isLogin = false router.beforeEach((to, from, next) => {if (to.path === '/one' && isLogin === false) {alert('請登錄')next(false) // 阻止路由跳轉} else {next() // 正常運行} })// 創建路由對象 const router = new VueRouter({routes,}) // 改正只需調換順序即可總結
以上是生活随笔為你收集整理的Cannot access ‘router‘ before initialization的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HCIP之OSPF(五)
- 下一篇: HDU - 1824 Let's go