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) => {
|
2020-05-02 20:54:21 +08:00
|
|
|
console.log("before:")
|
2020-05-02 01:25:28 +08:00
|
|
|
console.log(to)
|
|
|
|
next()
|
|
|
|
})
|
|
|
|
|
|
|
|
router.afterEach(to => {
|
2020-05-02 20:54:21 +08:00
|
|
|
console.log("after:")
|
2020-05-02 01:25:28 +08:00
|
|
|
console.log(to)
|
|
|
|
})
|
|
|
|
|
|
|
|
export default router
|