zrlibs
2025-03-17 6e7fcc0ebecb4d9d1485937905b31a9864913950
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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