vue中的 mode:history 与路由的router.beforeEach钩子能共存吗?
今天遇到一个问题,在路由定义的js中使用mode:history import Vue from 'vue' import Router from 'vue-router' import login from '@/components/login' import index from '@/views/index' Vue . use ( Router ) export default new Router ({ mode: 'history' , routes: [ { path: '/login' , name: 'login' , component: login }, { path: '/index' , name: 'index' , component: index } ] }) 然后再main.js中使用路由的生命钩子进行登录控制 router . beforeEach (( to , from , next ) => { if ( to . path != '/login' ) { next ({ path: '/login' }) } else { next () } }) 但是在页面使用时,我访问index对应的页面却没有跳转login。如果去掉mode:history 重启项目后 就可以使用了 这是不是因为i这两者之间冲突 还是我写的不对呀 有没有大佬帮看下