|
1
2
3
4
|
import type { RouteRecordRaw } from 'vue-router';
import type { App } from 'vue';
import { createRouter, createWebHashHistory } from 'vue-router';
|
Vben
authored
|
5
|
import { basicRoutes, LoginRoute } from './routes';
|
|
6
|
import { REDIRECT_NAME } from './constant';
|
|
7
|
|
Vben
authored
|
8
9
|
const WHITE_NAME_LIST = [LoginRoute.name, REDIRECT_NAME];
|
|
10
11
|
// app router
const router = createRouter({
|
Vben
authored
|
12
|
history: createWebHashHistory(import.meta.env.VITE_PUBLIC_PATH),
|
vben
authored
|
13
|
routes: (basicRoutes as unknown) as RouteRecordRaw[],
|
vben
authored
|
14
|
strict: true,
|
vben
authored
|
15
|
scrollBehavior: () => ({ left: 0, top: 0 }),
|
|
16
|
});
|
vben
authored
|
17
|
|
|
18
19
20
21
|
// reset router
export function resetRouter() {
router.getRoutes().forEach((route) => {
const { name } = route;
|
Vben
authored
|
22
|
if (name && !WHITE_NAME_LIST.includes(name as string)) {
|
vben
authored
|
23
|
router.hasRoute(name) && router.removeRoute(name);
|
|
24
25
26
27
28
29
30
31
32
33
|
}
});
}
// config router
export function setupRouter(app: App<Element>) {
app.use(router);
}
export default router;
|