Skip to content

Commit

Permalink
add useBasenameRelativeNavigate hook for base path navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
hervedombya committed Jan 17, 2025
1 parent 4b53cde commit b9da254
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ModuleFederation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import React, {
useMemo,
useSyncExternalStore,
} from "react";
import { NavigateOptions, To, useNavigate } from "react-router";
type Module = any;

const registeredApps: string[] = [];
Expand Down Expand Up @@ -287,3 +288,14 @@ export const ShellHooksProvider = <
}, [shellHooks, shellAlerts]);
return <>{children}</>;
};

export const useBasenameRelativeNavigate = () => {
const originalNavigate = useNavigate();
const { appHistoryBasePath } = useCurrentApp();

const navigate = (to: To, options?: NavigateOptions) => {
return originalNavigate(`${appHistoryBasePath}${to}`, options);
};

return navigate;
};

0 comments on commit b9da254

Please sign in to comment.