Skip to content

Commit 66d1bfe

Browse files
committed
fix(kit): filter useless route info, closes #159
1 parent 5e14c2a commit 66d1bfe

File tree

1 file changed

+28
-6
lines changed
  • packages/devtools-kit/src/core/router

1 file changed

+28
-6
lines changed

packages/devtools-kit/src/core/router/index.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RouteLocationNormalizedLoaded, RouteRecordNormalized, Router } from 'vue-router'
1+
import type { RouteLocationNormalizedLoaded, RouteRecordNormalized, RouteRecordRaw, Router } from 'vue-router'
22
import type { AppRecord } from '@vue/devtools-schema'
33
import { deepClone, target as global } from '@vue/devtools-shared'
44
import { debounce } from 'perfect-debounce'
@@ -34,17 +34,39 @@ export function normalizeRouterInfo(appRecord: AppRecord) {
3434
const routesMap = new Map()
3535
return (router?.getRoutes() || []).filter(i => !routesMap.has(i.path) && routesMap.set(i.path, 1))
3636
}
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+
4243
return {
4344
path,
4445
name,
4546
children,
4647
}
4748
})
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))
4870
const c = console.warn
4971
console.warn = () => {}
5072
global[RouterInfoKey] = {

0 commit comments

Comments
 (0)