| | |
| | | import type { RouteRecordRaw } from 'vue-router'; |
| | | import type { App } from 'vue'; |
| | | import type { App } from 'vue' |
| | | import type { RouteRecordRaw } from 'vue-router' |
| | | |
| | | import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'; |
| | | import { basicRoutes } from './routes'; |
| | | import { createRouter, createWebHistory } from 'vue-router' |
| | | import { basicRoutes } from './routes' |
| | | |
| | | // 白名单应该包含基本静态路由 |
| | | const WHITE_NAME_LIST: string[] = []; |
| | | const WHITE_NAME_LIST: string[] = [] |
| | | const getRouteNames = (array: any[]) => |
| | | array.forEach((item) => { |
| | | WHITE_NAME_LIST.push(item.name); |
| | | getRouteNames(item.children || []); |
| | | }); |
| | | getRouteNames(basicRoutes); |
| | | WHITE_NAME_LIST.push(item.name) |
| | | getRouteNames(item.children || []) |
| | | }) |
| | | getRouteNames(basicRoutes) |
| | | |
| | | // app router |
| | | export const router = createRouter({ |
| | |
| | | routes: basicRoutes as unknown as RouteRecordRaw[], |
| | | strict: true, |
| | | scrollBehavior: () => ({ left: 0, top: 0 }), |
| | | }); |
| | | }) |
| | | |
| | | // reset router |
| | | export function resetRouter() { |
| | | router.getRoutes().forEach((route) => { |
| | | const { name } = route; |
| | | const { name } = route |
| | | if (name && !WHITE_NAME_LIST.includes(name as string)) { |
| | | router.hasRoute(name) && router.removeRoute(name); |
| | | router.hasRoute(name) && router.removeRoute(name) |
| | | } |
| | | }); |
| | | }) |
| | | } |
| | | |
| | | // config router |
| | | export function setupRouter(app: App<Element>) { |
| | | app.use(router); |
| | | app.use(router) |
| | | } |