提交 | 用户 | 时间
|
314507
|
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({ |
8e4ab7
|
8 |
history: createWebHistory("/energy"), // createWebHashHistory URL带#,createWebHistory URL不带# |
314507
|
9 |
strict: true, |
H |
10 |
routes: remainingRouter as RouteRecordRaw[], |
|
11 |
scrollBehavior: () => ({ left: 0, top: 0 }) |
|
12 |
}) |
|
13 |
|
|
14 |
export const resetRouter = (): void => { |
8e4ab7
|
15 |
const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root', 'Callback'] |
314507
|
16 |
router.getRoutes().forEach((route) => { |
H |
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 |