diff --git a/apps/hosted-components/src/routes/__root.tsx b/apps/hosted-components/src/routes/__root.tsx index 55786d118..70c2cc9e7 100644 --- a/apps/hosted-components/src/routes/__root.tsx +++ b/apps/hosted-components/src/routes/__root.tsx @@ -1,6 +1,7 @@ /// import { StackClientApp, StackProvider, StackTheme } from '@hexclave/react'; import { publishableClientKeyNotNecessarySentinel } from '@hexclave/shared/dist/utils/oauth'; +import { runAsynchronously } from '@hexclave/shared/dist/utils/promises'; import { HeadContent, Outlet, @@ -49,6 +50,22 @@ function getApiBaseUrlFromEnv(): string | undefined { return import.meta.env.VITE_HEXCLAVE_API_URL ?? import.meta.env.VITE_STACK_API_URL ?? undefined; } +function useHexclaveNavigateAdapter() { + const navigate = useNavigate(); + + return useMemo(() => ({ + useNavigate: () => (to: string) => { + runAsynchronously(async () => { + if (to.startsWith("#")) { + await navigate({ hash: to.slice(1) }); + } else { + await navigate({ href: to }); + } + }); + }, + }), [navigate]); +} + function FullPageError({ title, message }: { title: string, message: string }) { return (
@@ -137,6 +154,7 @@ function RootDocument({ children }: { children: ReactNode }) { function RootComponent() { const projectId = useProjectIdFromHostname(); + const redirectMethod = useHexclaveNavigateAdapter(); const isValidProjectId = projectId ? (projectId === "internal" || /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(projectId)) : false; @@ -155,9 +173,9 @@ function RootComponent() { afterSignUp: "/", afterSignOut: "/handler/sign-in", }, - redirectMethod: { useNavigate: useNavigate as any } + redirectMethod, }); - }, [isValidProjectId, projectId]); + }, [isValidProjectId, projectId, redirectMethod]); if (projectId === undefined) { return ;