import Vue from 'vue'
|
import Router from 'vue-router'
|
import { routes } from './routes'
|
import 'nprogress/nprogress.css'
|
const appConfig = require('@/app.config')
|
const { routeMode } = appConfig
|
|
Vue.use(Router)
|
const baseName = process.env.NODE_ENV === 'production' ? `/${appConfig.projectName}/` : '/'
|
const router = new Router({
|
base: baseName,
|
mode: routeMode || 'hash',
|
routes: routes
|
})
|
router.beforeEach((to, from, next) => {
|
Vue.prototype.$cancels.forEach((cancel) => {
|
cancel()
|
})
|
Vue.prototype.$cancels = []
|
// 不需要登录认证的路由
|
if (Object.hasOwnProperty.call(to.meta, 'noLoginIdentify') && to.meta.noLoginIdentify) {
|
next()
|
return
|
}
|
next()
|
})
|
router.beforeResolve((to, from, next) => {
|
next()
|
})
|
router.afterEach((to, from) => {
|
})
|
export default router
|