Skip to content

Regarding how to elegantly redirect in createBrowserRouter #10556

Closed Answered by mrsrhn
bmcswrdd5977 asked this question in Q&A
Discussion options

You must be logged in to vote

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} />
);

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@brophdawg11
Comment options

@tptodorov
Comment options

Answer selected by brophdawg11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants