Blame view

src/router/index.ts 1013 Bytes
陈文彬 authored
1
2
3
4
import type { RouteRecordRaw } from 'vue-router';
import type { App } from 'vue';

import { createRouter, createWebHashHistory } from 'vue-router';
vben authored
5
陈文彬 authored
6
7
8
import { createGuard } from './guard/';

import { basicRoutes } from './routes/';
vben authored
9
import { scrollBehavior } from './scrollBehavior';
10
import { REDIRECT_NAME } from './constant';
陈文彬 authored
11
12
13

// app router
const router = createRouter({
14
  history: createWebHashHistory(),
陈文彬 authored
15
  routes: basicRoutes as RouteRecordRaw[],
16
  strict: true,
vben authored
17
  scrollBehavior: scrollBehavior,
陈文彬 authored
18
});
vben authored
19
陈文彬 authored
20
21
// reset router
export function resetRouter() {
22
  const resetWhiteNameList = ['Login', REDIRECT_NAME];
陈文彬 authored
23
24
25
  router.getRoutes().forEach((route) => {
    const { name } = route;
    if (name && !resetWhiteNameList.includes(name as string)) {
vben authored
26
      router.hasRoute(name) && router.removeRoute(name);
陈文彬 authored
27
28
29
30
31
32
33
34
35
36
    }
  });
}

// config router
export function setupRouter(app: App<Element>) {
  app.use(router);
  createGuard(router);
}
vben authored
37
38
39
// router.onError((error) => {
//   console.error(error);
// });
vben authored
40
陈文彬 authored
41
export default router;