createRoutesFromElements.js
import {
createBrowserRouter,
createRoutesFromElements,
RouterProvider,
} from "react-router-dom";
// You can do this:
const router = createBrowserRouter(
createRoutesFromElements(
<Route path="/" element={<Root />}>
<Route path="dashboard" element={<Dashboard />} />
<Route path="about" element={<About />} />
</Route>
)
);
// Instead of this:
function Router() {
const router = createBrowserRouter(
createRoutesFromElements(
<Route path="/" element={<App />}>
<Route path="dashboard" element={<Dashboard />} />
<Route path="about" element={<About />} />
</Route>
)
)
return <RouterProvider router={router} />
}
export default Router
// then call Router in main.jsx