export const routes = createRoutesFromElements(
<Route path="/" element={<Layout />}>
<Route path="home element={<Home />} />
<Route path="*" element={<AppLayout />}>
<Route path="sample" element={<Sample />} />
</Route>
</Route>
</Route>,
);
export const browserRouter = createBrowserRouter(routes);
and the router is used as
root.render(<RouterProvider router={browserRouter} />)
Finally, the problematic part, <Sample />
component where the error is thrown from is like this
const Sample = () => {
return (
<Route
path=""
element={
<div>
Sample
<Outlet />
</div>
}
>
<Route path="2" element={<div>dsf</div>}></Route>
</Route>
);
};
Creating the first router using createRoutesFromElements
works fine but in the <Sample />
component, the error A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.
is thrown.
I used to wrap with <Routes />
but since I want to leverage the full feature of data provider, I am migrating to not using the <Routes />
.
If I can't define all the routes in one place, how can I set up the route dynamically as above?