刚刚学习VUE脚手架的路由导航守卫功能
目录如下
router/index.js代码如下:
import Vue from 'vue'
import Router from 'vue-router'
import App_index from '@/components/app_index'
import App_article from '@/components/app_article'
import My from '@/components/my'
import Login from '@/components/login'
Vue.use(Router)
const auth = {
islogin(){
return false
}
}
export default new Router({
routes: [
{
path: '/',
name: 'App_index',
component: App_index
},{
path: '/app_article',
name: 'App_article',
component: App_article
},{
path: '/my',
name: 'My',
component: My
},{
path: '/login',
name: 'Login',
component: Login
}
]
})
Router.beforeEach((to, from, next) => {
if(to.path == '/my'){
if(auth.islogin()){
next()
}else{
next('/login')
}
}else{
next()
}
})
打卡项目后,首页报错:
__WEBPACK_IMPORTED_MODULE_1_vue_router__.a.beforeEach is not a function
空白无法显示
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…