|
1 |
| -import type { RouteLocationNormalizedLoaded, RouteRecordNormalized, Router } from 'vue-router' |
| 1 | +import type { RouteLocationNormalizedLoaded, RouteRecordNormalized, RouteRecordRaw, Router } from 'vue-router' |
2 | 2 | import type { AppRecord } from '@vue/devtools-schema'
|
3 | 3 | import { deepClone, target as global } from '@vue/devtools-shared'
|
4 | 4 | import { debounce } from 'perfect-debounce'
|
@@ -34,17 +34,39 @@ export function normalizeRouterInfo(appRecord: AppRecord) {
|
34 | 34 | const routesMap = new Map()
|
35 | 35 | return (router?.getRoutes() || []).filter(i => !routesMap.has(i.path) && routesMap.set(i.path, 1))
|
36 | 36 | }
|
37 |
| - function init() { |
38 |
| - const router = appRecord.app?.config.globalProperties.$router as Router | undefined |
39 |
| - const currentRoute = router?.currentRoute.value |
40 |
| - const routes = getRoutes(router).map((item) => { |
41 |
| - const { path, name, children } = item |
| 37 | + function filterRoutes(routes: RouteRecordRaw[]) { |
| 38 | + return routes.map((item) => { |
| 39 | + let { path, name, children } = item |
| 40 | + if (children?.length) |
| 41 | + children = filterRoutes(children) |
| 42 | + |
42 | 43 | return {
|
43 | 44 | path,
|
44 | 45 | name,
|
45 | 46 | children,
|
46 | 47 | }
|
47 | 48 | })
|
| 49 | + } |
| 50 | + function filterCurrentRoute(route: RouteLocationNormalizedLoaded & { href?: string } | undefined) { |
| 51 | + if (route) { |
| 52 | + const { fullPath, hash, href, path, name, matched, params, query } = route |
| 53 | + return { |
| 54 | + fullPath, |
| 55 | + hash, |
| 56 | + href, |
| 57 | + path, |
| 58 | + name, |
| 59 | + params, |
| 60 | + query, |
| 61 | + matched: filterRoutes(matched), |
| 62 | + } |
| 63 | + } |
| 64 | + return route |
| 65 | + } |
| 66 | + function init() { |
| 67 | + const router = appRecord.app?.config.globalProperties.$router as Router | undefined |
| 68 | + const currentRoute = filterCurrentRoute(router?.currentRoute.value) |
| 69 | + const routes = filterRoutes(getRoutes(router)) |
48 | 70 | const c = console.warn
|
49 | 71 | console.warn = () => {}
|
50 | 72 | global[RouterInfoKey] = {
|
|
0 commit comments