diff --git a/src/ModuleFederation.tsx b/src/ModuleFederation.tsx index 0c2d547..fe54cee 100644 --- a/src/ModuleFederation.tsx +++ b/src/ModuleFederation.tsx @@ -13,6 +13,7 @@ import React, { useMemo, useSyncExternalStore, } from "react"; +import { NavigateOptions, To, useNavigate } from "react-router"; type Module = any; const registeredApps: string[] = []; @@ -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; +};