feat(layout): 优化侧边栏菜单生成逻辑并增强类型安全
All checks were successful
CI/CD Pipeline / playwright (push) Successful in 2m11s
CI/CD Pipeline / build-and-deploy (push) Successful in 4m15s

This commit is contained in:
严浩
2025-10-22 13:22:04 +08:00
parent 4949e1c957
commit e95d883c23
4 changed files with 42 additions and 54 deletions

View File

@@ -2,7 +2,7 @@ import { DataLoaderPlugin } from 'unplugin-vue-router/data-loaders';
import { setupLayouts } from 'virtual:meta-layouts';
// import { createGetRoutes, setupLayouts } from 'virtual:generated-layouts';
import { createRouter, createWebHistory } from 'vue-router';
import { handleHotUpdate, routes } from 'vue-router/auto-routes';
import { routes, handleHotUpdate } from 'vue-router/auto-routes';
const setupLayoutsResult = setupLayouts(routes);
const router = createRouter({
@@ -14,12 +14,10 @@ const router = createRouter({
strict: true,
});
if (__DEV__) Object.assign(globalThis, { router });
router.onError((error) => {
console.debug('🚨 [router error]:', error);
});
export { router, setupLayoutsResult };
export function install({ app }: { app: import('vue').App<Element> }) {
app
// 在路由之前注册插件
@@ -37,12 +35,8 @@ export function install({ app }: { app: import('vue').App<Element> }) {
Object.assign(globalThis, { stack: createStackGuard(router) });
}
/*
definePage({
meta: { },
});
*/
declare module 'vue-router' {
/* definePage({ meta: { title: '示例演示' } }); */
interface RouteMeta {
/**
* @description 是否在菜单中隐藏
@@ -60,7 +54,11 @@ declare module 'vue-router' {
}
}
export { router, setupLayoutsResult };
export { createGetRoutes } from 'virtual:meta-layouts';
if (__DEV__) Object.assign(globalThis, { router });
// This will update routes at runtime without reloading the page
if (import.meta.hot) handleHotUpdate(router);
if (import.meta.hot) {
handleHotUpdate(router);
}