Skip to content

Commit

Permalink
fix(kit): filter useless route info, closes #159
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz committed Jan 14, 2024
1 parent 5e14c2a commit 66d1bfe
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions packages/devtools-kit/src/core/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RouteLocationNormalizedLoaded, RouteRecordNormalized, Router } from 'vue-router'
import type { RouteLocationNormalizedLoaded, RouteRecordNormalized, RouteRecordRaw, Router } from 'vue-router'
import type { AppRecord } from '@vue/devtools-schema'
import { deepClone, target as global } from '@vue/devtools-shared'
import { debounce } from 'perfect-debounce'
Expand Down Expand Up @@ -34,17 +34,39 @@ export function normalizeRouterInfo(appRecord: AppRecord) {
const routesMap = new Map()
return (router?.getRoutes() || []).filter(i => !routesMap.has(i.path) && routesMap.set(i.path, 1))
}
function init() {
const router = appRecord.app?.config.globalProperties.$router as Router | undefined
const currentRoute = router?.currentRoute.value
const routes = getRoutes(router).map((item) => {
const { path, name, children } = item
function filterRoutes(routes: RouteRecordRaw[]) {
return routes.map((item) => {
let { path, name, children } = item
if (children?.length)
children = filterRoutes(children)

return {
path,
name,
children,
}
})
}
function filterCurrentRoute(route: RouteLocationNormalizedLoaded & { href?: string } | undefined) {
if (route) {
const { fullPath, hash, href, path, name, matched, params, query } = route
return {
fullPath,
hash,
href,
path,
name,
params,
query,
matched: filterRoutes(matched),
}
}
return route
}
function init() {
const router = appRecord.app?.config.globalProperties.$router as Router | undefined
const currentRoute = filterCurrentRoute(router?.currentRoute.value)
const routes = filterRoutes(getRoutes(router))
const c = console.warn
console.warn = () => {}
global[RouterInfoKey] = {
Expand Down

0 comments on commit 66d1bfe

Please sign in to comment.