import routes from './routes'
|
import { createRouter, createWebHashHistory } from 'vue-router'
|
import ViewUIPlus from 'view-ui-plus'
|
import { checkLogin } from '@/libs/util'
|
var router = createRouter({
|
routes: routes,
|
history: createWebHashHistory(),
|
})
|
router.beforeEach((to, from, next) => {
|
ViewUIPlus.LoadingBar.start();
|
// 按项目实际需求修改标题
|
document.title = to.meta.title
|
if (to.matched.some(t => t.meta.authorize) && !checkLogin()) {
|
next({ name: 'login' })
|
}
|
else {
|
next()
|
}
|
})
|
router.afterEach(() => {
|
ViewUIPlus.LoadingBar.finish()
|
})
|
// 路由加载出错
|
router.onError((err) => {
|
ViewUIPlus.LoadingBar.error()
|
// 按项目实际需求处理错误异常
|
throw new Error(err)
|
})
|
|
export default router
|