Regarding how to elegantly redirect in createBrowserRouter #10556
-
So, in latest documentation.We can const router = createBrowserRouter([
{
path: "/",
element: <Root />,
loader: rootLoader,
children: [
{
path: "team",
element: <Team />,
loader: teamLoader,
},
],
},
]);
ReactDOM.createRoot(document.getElementById("root")).render(
<RouterProvider router={router} />
); But actually, we need redirect at most. const router = createBrowserRouter([
{
path: "/",
element: <Root />,
loader: rootLoader,
redirect: '/team',
children: [
{
path: "team",
element: <Team />,
loader: teamLoader,
},
],
},
]);
ReactDOM.createRoot(document.getElementById("root")).render(
<RouterProvider router={router} />
); I known something like this |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
This is a React Router question. Moving this discussion to that repository. |
Beta Was this translation helpful? Give feedback.
-
This worked for us: const router = createBrowserRouter([
{
path: "/",
element: <Root />,
loader: rootLoader,
children: [
{
index: true,
loader: async () => redirect('/team'),
},
{
path: "team",
element: <Team />,
loader: teamLoader,
},
],
},
]);
ReactDOM.createRoot(document.getElementById("root")).render(
<RouterProvider router={router} />
); |
Beta Was this translation helpful? Give feedback.
This worked for us: