goindex-theme-r/src/router/index.js

45 lines
937 B
JavaScript
Raw Normal View History

2020-05-02 01:25:28 +08:00
import Vue from 'vue'
import VueRouter from 'vue-router'
// 路由数据
import routes from './routes'
// fix vue-router NavigationDuplicated
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
return VueRouterPush.call(this, location).catch(err => err)
}
const VueRouterReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace (location) {
return VueRouterReplace.call(this, location).catch(err => err)
}
Vue.use(VueRouter)
// 导出路由 在 main.js 里使用
const router = new VueRouter({
mode: 'history',
/* scrollBehavior(to,from,savePosition){
if(savePosition) {
return savePosition;
}else{
return {x:0,y:0}
}
}, */
routes
})
/**
* 路由拦截
* 权限验证
*/
router.beforeEach(async (to, from, next) => {
console.log(to)
next()
})
router.afterEach(to => {
console.log(to)
})
export default router