import type { RouteRecordRaw } from 'vue-router'; import { routes } from './router'; export type RouteWithFullPath = RouteRecordRaw & { fullPath: string }; const joinPath = (parentPath: string, childPath: string): string => { if (childPath.startsWith('/')) { return childPath; } if (childPath === '') { return parentPath || '/'; } return parentPath === '/' ? `/${childPath}` : `${parentPath}/${childPath}`; }; const flatMapRoutes = ( route: RouteRecordRaw, parentPath: string = '' ): RouteWithFullPath[] => { const fullPath = joinPath(parentPath, route.path ?? ''); const routeWithPath = { ...route, fullPath } as RouteWithFullPath; const childRoutes = route.children?.flatMap(child => flatMapRoutes(child, fullPath)) || []; return [routeWithPath, ...childRoutes]; }; export const getAllRoutes = (): RouteWithFullPath[] => { return routes.flatMap(route => flatMapRoutes(route)); };