0

Is there a way to make a route the default route without using "/"? I want the route below to be the route users see when they open my page, but I don't want to change the path name.

    <Route path="/about" element={<About />}></Route>
  • 1
    Your question doesn't make sense. When users "open your page" they will open the `/` route. If they don't, and go directly to `/about` then the above will work. If you want to forward your `/` visitors to `/about` then use a redirect. Otherwise just serve the same component on the the `/` route as well. – Christian Fritz Mar 02 '23 at 17:38
  • As Christian says, you have to register `/` as a route for react router to know what to do with it. With that said, you can create two routs to the same component, so you only have to add one line of code. – Code-Apprentice Mar 02 '23 at 17:41

1 Answers1

1

With a Redirect. If you are using react-router-dom@5 (or below), you can use a Redirect component. In your Route manager:

<Route exact path="/">
    <Redirect to="/about" />
</Route>

Otherwise, when using react-router-dom@6, please refer to this question.

Gabriele Serra
  • 381
  • 3
  • 10