Blame view

src/router/index.ts 897 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 './scrollBehaviour';
陈文彬 authored
10
11
12
13
14

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

// config router
export function setupRouter(app: App<Element>) {
  app.use(router);
  createGuard(router);
}

export default router;