Skip to content

Commit

Permalink
fix(projects): dts and transform supports multilevel routing user-def…
Browse files Browse the repository at this point in the history
…ined jump subpages
  • Loading branch information
mufeng889 committed Jul 29, 2024
1 parent d2c0e25 commit 4b9c1e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/route-core/dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ declare module "@elegant-router/types" {
name: K;
path: RouteMap[K];
component: \`${LAYOUT_PREFIX}\${RouteLayout}$${VIEW_PREFIX}\${K}\`| \`${VIEW_PREFIX}\${LastLevelRouteKey}\`;
children?:ElegantConstRoute[] ;
layout?:${layoutType}
}
: never;
Expand Down Expand Up @@ -244,7 +245,7 @@ declare module "@elegant-router/types" {
? Omit<ElegantConstRoute, 'children'> & {
name: K;
path: RouteMap[K];
component?: \`${LAYOUT_PREFIX}\${RouteLayout}$${VIEW_PREFIX}\${LastLevelRouteKey}\`| \`${VIEW_PREFIX}\${LastLevelRouteKey}\`;
component?: \`${LAYOUT_PREFIX}\${RouteLayout}$${VIEW_PREFIX}\${LastLevelRouteKey}\`| \`${VIEW_PREFIX}\${LastLevelRouteKey}\`| \`$${VIEW_PREFIX}\${LastLevelRouteKey}\`;
layout?:${layoutType}
}
: never;
Expand Down
22 changes: 11 additions & 11 deletions src/route-core/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function getTransformCode(options: ElegantReactRouterOption, entries: ElegantRou
import type { LazyRouteFunction, RouteObject,IndexRouteObject } from "react-router-dom";
import type { FunctionComponent } from "react";
import type { ElegantConstRoute } from @ohh-889/react-auto-route';
import type { ElegantConstRoute } from '@ohh-889/react-auto-route';
import type { RouteMap, RouteKey, RoutePath } from '@elegant-router/types';
import { redirect } from 'react-router-dom'
import ErrorBoundary from '@/pages/_builtin/error'
Expand Down Expand Up @@ -113,7 +113,7 @@ export function transformElegantRouteToReactRoute(
const [layout, view] = component.split(FIRST_LEVEL_ROUTE_COMPONENT_SPLIT);
return {
layout: getLayoutName(layout),
layout: layout?getLayoutName(layout):undefined,
view: getViewName(view)
};
}
Expand Down Expand Up @@ -190,25 +190,25 @@ export function transformElegantRouteToReactRoute(
return {};
}
if (redirectTo) {
reactRoute.loader=()=>redirect(redirectTo)
}
if (loader) {
reactRoute.loader = () => loader
}
if (children?.length) {
reactRoute.children = children.flatMap(child => transformElegantRouteToReactRoute(child, layouts, views));
const defaultRedirectPath = redirectTo || getRedirectPath(path as string, children[0].path as string);
if (!redirectTo) {
reactRoute.children.unshift({
index: true,
loader: () => redirect(getRedirectPath(path as string,children[0].path as string) ),
loader: () => redirect(defaultRedirectPath),
...rest
});
}
}else if (redirectTo) {
reactRoute.loader=()=>redirect(redirectTo)
}
if (loader) {
reactRoute.loader = () => loader
}
if (layout) {
Expand Down

0 comments on commit 4b9c1e3

Please sign in to comment.