Skip to content

Commit 72d1627

Browse files
committed
feat: consume MODERN_ROUTER_ID_PREFIX
1 parent f1c7477 commit 72d1627

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.changeset/nice-bags-exist.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modern-js/runtime': patch
3+
---
4+
5+
feat: consume MODERN_ROUTER_ID_PREFIX

packages/runtime/plugin-runtime/src/router/runtime/index.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useRouteLoaderData as useRouteData } from '@modern-js/runtime-utils/rou
22
import { routerPlugin } from './plugin';
33
import type { SingleRouteConfig, RouterConfig } from './types';
44

5+
declare const MODERN_ROUTER_ID_PREFIX: string | undefined;
56
export * from '@modern-js/runtime-utils/router';
67

78
export type { SingleRouteConfig, RouterConfig };
@@ -18,7 +19,13 @@ export { Link, NavLink } from './PrefetchLink';
1819
export type { LinkProps, NavLinkProps } from './PrefetchLink';
1920

2021
export const useRouteLoaderData: typeof useRouteData = (routeId: string) => {
21-
const realRouteId = routeId.replace(/\[(.*?)\]/g, '($1)');
22+
const routerIdPrefix =
23+
typeof MODERN_ROUTER_ID_PREFIX === 'string' ? MODERN_ROUTER_ID_PREFIX : '';
24+
let routeIdWithOutPrefix = routeId;
25+
if (routeId.includes(routerIdPrefix)) {
26+
routeIdWithOutPrefix = routeId.replace(routerIdPrefix, '');
27+
}
28+
const realRouteId = routeIdWithOutPrefix.replace(/\[(.*?)\]/g, '($1)');
2229
return useRouteData(realRouteId);
2330
};
2431

0 commit comments

Comments
 (0)