|
@@ -4,12 +4,12 @@ import { computed } from 'vue'
|
|
import { RoutesName } from './constant'
|
|
import { RoutesName } from './constant'
|
|
import { metas } from './constant'
|
|
import { metas } from './constant'
|
|
|
|
|
|
-import type { RouteRecordRaw, RouteRecordName } from 'vue-router'
|
|
|
|
|
|
+import { RouteRaw } from './config'
|
|
|
|
|
|
export const history = createWebHashHistory()
|
|
export const history = createWebHashHistory()
|
|
export const router = createRouter({ history, routes })
|
|
export const router = createRouter({ history, routes })
|
|
|
|
|
|
-export const getRouteTree = (name: RouteRecordName, raw: RouteRecordRaw[] = routes): void | RouteRecordRaw => {
|
|
|
|
|
|
+export const getRouteTree = (name: RoutesName, raw: RouteRaw[] = routes): void | RouteRaw => {
|
|
for (const route of raw) {
|
|
for (const route of raw) {
|
|
if (route.name === name) {
|
|
if (route.name === name) {
|
|
return route
|
|
return route
|
|
@@ -22,9 +22,9 @@ export const getRouteTree = (name: RouteRecordName, raw: RouteRecordRaw[] = rout
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-export const getRouteNames = (name: RouteRecordName, raw: RouteRecordRaw[] = routes): RouteRecordName[] => {
|
|
|
|
|
|
+export const getRouteNames = (name: RoutesName, raw: RouteRaw[] = routes): RoutesName[] => {
|
|
let current = getRouteTree(name, raw)
|
|
let current = getRouteTree(name, raw)
|
|
- const names: RouteRecordName[] = []
|
|
|
|
|
|
+ const names: RoutesName[] = []
|
|
while (current) {
|
|
while (current) {
|
|
names.push(current.name!)
|
|
names.push(current.name!)
|
|
current = current.children && current.children[0]
|
|
current = current.children && current.children[0]
|
|
@@ -32,15 +32,15 @@ export const getRouteNames = (name: RouteRecordName, raw: RouteRecordRaw[] = rou
|
|
return names
|
|
return names
|
|
}
|
|
}
|
|
|
|
|
|
-export const getRouteConfig = (name: RouteRecordName, raw: RouteRecordRaw[] = routes): RouteRecordRaw | void => {
|
|
|
|
|
|
+export const getRouteConfig = (name: RoutesName, raw: RouteRaw[] = routes): RouteRaw | void => {
|
|
let current = getRouteTree(name, raw)
|
|
let current = getRouteTree(name, raw)
|
|
- while (current) {
|
|
|
|
- current = current.children && current.children[0]
|
|
|
|
|
|
+ while (current?.children && current.children[0]) {
|
|
|
|
+ current = current.children[0]
|
|
}
|
|
}
|
|
return current
|
|
return current
|
|
}
|
|
}
|
|
|
|
|
|
-export const currentRouteNames = computed(() => getRouteNames(router.currentRoute.value.name!, routes))
|
|
|
|
|
|
+export const currentRouteNames = computed(() => getRouteNames(router.currentRoute.value.name as RoutesName, routes))
|
|
|
|
|
|
export const currentLayout = computed(() => {
|
|
export const currentLayout = computed(() => {
|
|
const names = currentRouteNames.value
|
|
const names = currentRouteNames.value
|
|
@@ -57,6 +57,5 @@ export const currentMeta = computed(() => {
|
|
|
|
|
|
export * from './config'
|
|
export * from './config'
|
|
export * from './constant'
|
|
export * from './constant'
|
|
-export type { RouteRecordRaw }
|
|
|
|
|
|
|
|
export default router
|
|
export default router
|