File tree 2 files changed +13
-1
lines changed
packages/runtime/plugin-runtime/src/router/runtime
2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @modern-js/runtime ' : patch
3
+ ---
4
+
5
+ feat: consume MODERN_ROUTER_ID_PREFIX
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { useRouteLoaderData as useRouteData } from '@modern-js/runtime-utils/rou
2
2
import { routerPlugin } from './plugin' ;
3
3
import type { SingleRouteConfig , RouterConfig } from './types' ;
4
4
5
+ declare const MODERN_ROUTER_ID_PREFIX : string | undefined ;
5
6
export * from '@modern-js/runtime-utils/router' ;
6
7
7
8
export type { SingleRouteConfig , RouterConfig } ;
@@ -18,7 +19,13 @@ export { Link, NavLink } from './PrefetchLink';
18
19
export type { LinkProps , NavLinkProps } from './PrefetchLink' ;
19
20
20
21
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)' ) ;
22
29
return useRouteData ( realRouteId ) ;
23
30
} ;
24
31
You can’t perform that action at this time.
0 commit comments