Skip to content

Commit

Permalink
apply staticProps when soft navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
codehz committed Aug 16, 2024
1 parent 2365703 commit 9d17397
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion hydrate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export async function hydrate(
const Initial = await import(matched.value);
return hydrateRoot(
document,
<RouterHost Shell={Shell} {...options}>
<RouterHost
Shell={Shell}
staticProps={globalX.__STATIC_PROPS__}
{...options}
>
<Shell
route={globalX.__INITIAL_ROUTE__}
{...globalX.__STATIC_PROPS__}
Expand Down
4 changes: 3 additions & 1 deletion router/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ export const RouterHost = ({
normalizeUrl = (url: string) => url,
Shell,
onRouteUpdated,
staticProps,
}: {
children: React.ReactElement;
normalizeUrl?: (url: string) => string;
Shell: React.ComponentType<{ children: React.ReactElement; route?: string }>;
onRouteUpdated?: (path: string) => void;
staticProps?: Record<string, unknown>;
}) => {
const pathname = useLocationProperty(
() => normalizeUrl(location.pathname + location.search),
Expand All @@ -135,7 +137,7 @@ export const RouterHost = ({
onRouteUpdated?.(target);
setVersion(currentVersion);
setCurrent(
<Shell route={target} {...props}>
<Shell route={target} {...staticProps} {...props}>
<module.default {...props?.props} />
</Shell>
);
Expand Down

0 comments on commit 9d17397

Please sign in to comment.