optimize: 优化代码质量

This commit is contained in:
xlsea
2025-05-13 23:13:23 +08:00
parent 7511fcbd51
commit 414cdbb8bd
6 changed files with 8 additions and 108 deletions

View File

@ -6,7 +6,6 @@
import type { RouteRecordRaw, RouteComponent } from 'vue-router';
import type { ElegantConstRoute } from '@elegant-router/vue';
import type { RouteMap, RouteKey, RoutePath } from '@elegant-router/types';
import { createCustomNameComponent, RouteComponentLoader } from './helper';
/**
* transform elegant const routes to vue routes
@ -126,11 +125,8 @@ function transformElegantRouteToVueRoute(
if (isView(component)) {
const viewName = getViewName(component);
// 给组件设置name 与route.name一致
vueRoute.component = createCustomNameComponent(views[viewName] as RouteComponentLoader,
{ name: route.name });
// 路由名称与组件名称保持一致解决keepAlive问题
vueRoute.name = route.name;
vueRoute.component = views[viewName];
}
}

View File

@ -96,11 +96,11 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
route.path = route.path.startsWith('//') ? route.path.substring(1) : route.path;
route.path = parent ? parent.path + route.path : route.path;
// route.name = route.component!;
// if (['layout.base', 'iframe-page'].includes(route.component!)) {
const name = humpToLine(route.path.substring(1).replace('/', '_'));
route.name = parent ? `${parent.name}_${name}` : name;
// }
route.name = route.component!;
if (['layout.base', 'iframe-page'].includes(route.component!)) {
const name = humpToLine(route.path.substring(1).replace('/', '_'));
route.name = parent ? `${parent.name}_${name}` : name;
}
route.meta = route.meta ? route.meta : { title: route.name };