I need to use a hash router with a basename. I did this with the createHashRouter (React Router 6.8), with the basename property to render the app in the sub-route. When I open /sub/route
in the browser I get the empty page though, only css background is visible.
All of the files and assets are shipped to the app, but the JS is not executed and the root div stays empty.
The code of the Router:
const router = createHashRouter([
{
id: 'root',
path: '/',
element: <App />,
errorElement: <ErrorPage />,
loader: filtersLoader(queryClient),
children: [
{ path: '/', element: <Navigate to="/dashboard/performance" /> },
{
path: '/dashboard',
id: 'dashboard',
errorElement: <ErrorPage />,
loader: dataLoader(queryClient),
element: (
<>
<Header />
<Outlet />
</>
),
children: [
{ index: true, element: <Index /> }
]
},
{
path: 'info',
element: <Info />
}
]
}
], {
basename: '/sub/route'
});
Update/solution
the issue was caused by mixing HashRouter with basename. Getting rid of the basename in createHashRouter solved the issue.