Skip to content

Commit d54a734

Browse files
dashboard: compute Router basename at runtime from hostname
The Vite-built bundle hard-coded BrowserRouter basename='/dashboard' to match the production path prefix. After the subdomain split that broke console.zeroauth.dev/signup (and every other route there): the URL no longer carries /dashboard, so the router refused to match anything and React rendered nothing — the user saw a black page and the warn 'Router basename=/dashboard is not able to match the URL /signup'. Vite base still has to be /dashboard/ because the JS+CSS bundle is served from /dashboard/assets/* on every host (Express mounts it there and Caddy passes the path through). But URL routing is a runtime concern, so resolve the basename from window.location: console.* hosts use '/', everything else (apex /dashboard legacy paths + localhost dev where Vite serves at /dashboard/) keeps the prefix.
1 parent 9147f73 commit d54a734

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎dashboard/src/App.tsx‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ import { Audit } from './routes/Audit';
1717
import { Settings } from './routes/Settings';
1818
import { NotFound } from './routes/NotFound';
1919

20+
/**
21+
* Router basename has to track where the dashboard is mounted, which
22+
* differs by host:
23+
* - console.zeroauth.dev/* → SPA lives at the root, basename = "/"
24+
* - zeroauth.dev/dashboard/* (legacy) and localhost dev (Vite serves
25+
* at /dashboard/ to match the production prefix) → basename = "/dashboard"
26+
*
27+
* Build-time Vite base is "/dashboard/" because the JS+CSS bundle has
28+
* to load from /dashboard/assets/* on every host (Express mounts the
29+
* static files there); but URL routing is a runtime concern, so we
30+
* compute it from window.location instead of from import.meta.env.
31+
*/
32+
function resolveBasename(): string {
33+
if (typeof window === 'undefined') return '/dashboard';
34+
if (window.location.hostname.startsWith('console.')) return '/';
35+
return '/dashboard';
36+
}
37+
2038
const queryClient = new QueryClient({
2139
defaultOptions: {
2240
queries: {
@@ -50,7 +68,7 @@ function RequireAuth() {
5068

5169
export function App() {
5270
return (
53-
<BrowserRouter basename="/dashboard">
71+
<BrowserRouter basename={resolveBasename()}>
5472
<QueryClientProvider client={queryClient}>
5573
<ThemeProvider>
5674
<AuthProvider>

0 commit comments

Comments
 (0)