Files
aiot-platform-ui/apps/web-ele/src/utils/routerHelper.ts

38 lines
924 B
TypeScript
Raw Normal View History

2025-10-30 16:33:33 +08:00
import type {
RouteLocationNormalized,
RouteRecordNormalized,
} from 'vue-router';
import { defineAsyncComponent } from 'vue';
const modules = import.meta.glob('../views/**/*.{vue,tsx}');
/**
*
* @param componentPath :/bpm/oa/leave/detail
*/
2025-10-14 10:21:57 +08:00
export function registerComponent(componentPath: string) {
for (const item in modules) {
if (item.includes(componentPath)) {
// 使用异步组件的方式来动态加载组件
return defineAsyncComponent(modules[item] as any);
}
}
2025-10-14 10:21:57 +08:00
}
2025-10-30 16:33:33 +08:00
export const getRawRoute = (
route: RouteLocationNormalized,
): RouteLocationNormalized => {
if (!route) return route;
const { matched, ...opt } = route;
return {
...opt,
matched: (matched
? matched.map((item) => ({
meta: item.meta,
name: item.name,
path: item.path,
}))
: undefined) as RouteRecordNormalized[],
};
};