我使用vue-cli创建了这个项目,目前正在学习vue-路由器。
我想使用beforeEach函数进行身份验证,以及我所看到的将新路由器函数传递给像var new_value = new Router这样的变量的所有教程。
这就是我的路由器的样子
router.vue
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/about',
name: 'about',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
}
]
})
我想要实现的是:
var new_router = new Router({ // pass the value to new_router
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/about',
name: 'about',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
}
]
})
当我这样做的时候,我得到了一个Cannot read property type错误。我是新来的。
发布于 2018-11-13 01:24:50
我以为问题在于出口。
var new_router = new Router({/*Your Options*/});做你想做的事:
router.beforeEach(async (to, from, next) => {
// Authentication Checking
});你必须出口
export default new_router;https://stackoverflow.com/questions/53272318
复制相似问题