beforeEach这个函数可以实现路由跳转的拦截,,但是有个很大问题。。。。
原以为
router.beforeEach((to, from, next) => {
console.log('cheshi')
next({path: '/eleform'})
})
可以直接跳转到我想要的页面,,但是其实又进去了beforeEach函数。。
测试一下:最后报错,说明前面的猜测是对的
可见只有调用了next()才能使得跳转停下来。。修改一下代码
router.beforeEach((to, from, next) => {
console.log('cheshi')
if (to.path === '/eleform') {
next()
}
next({path: '/eleform'})
})
测试OK。。。