提交 | 用户 | 时间
|
820397
|
1 |
import type { App } from 'vue' |
H |
2 |
import type { RouteRecordRaw } from 'vue-router' |
|
3 |
import { createRouter, createWebHistory } from 'vue-router' |
|
4 |
import remainingRouter from './modules/remaining' |
|
5 |
|
|
6 |
// 创建路由实例 |
|
7 |
const router = createRouter({ |
221c1c
|
8 |
history: createWebHistory(import.meta.env.VITE_BASE_PATH), // createWebHashHistory URL带#,createWebHistory URL不带# |
820397
|
9 |
strict: true, |
H |
10 |
routes: remainingRouter as RouteRecordRaw[], |
|
11 |
scrollBehavior: () => ({ left: 0, top: 0 }) |
|
12 |
}) |
|
13 |
|
|
14 |
export const resetRouter = (): void => { |
|
15 |
const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root'] |
|
16 |
router.getRoutes().forEach((route) => { |
|
17 |
const { name } = route |
|
18 |
if (name && !resetWhiteNameList.includes(name as string)) { |
|
19 |
router.hasRoute(name) && router.removeRoute(name) |
|
20 |
} |
|
21 |
}) |
|
22 |
} |
|
23 |
|
|
24 |
export const setupRouter = (app: App<Element>) => { |
|
25 |
app.use(router) |
|
26 |
} |
|
27 |
|
|
28 |
export default router |