Reputation: 146
I am trying to redirect my application to a specific route at starting of app. I tried this
<Route exact path="/todos" component={Todo} />
<Route exact path="/users" component={User} />
<Redirect path="/" to="/todos" />
But It has 2 issues
You tried to redirect to the same route you're currently on: "/todos"
I want to achieve the redirection concept as it is in Angular like we do:
{ path: '', redirectTo: '/heroes', pathMatch: 'full' },
Upvotes: 0
Views: 817
Reputation: 2684
You'd need to wrap them in a <Switch>
, for example:
<Switch>
<Route exact path="/todos" component={Todo} />
<Route exact path="/users" component={User} />
<Redirect from="/" to="/todos" />
</Switch>
It will match the routes in order. So for example: if you have /todos, it will match the first one, if you have /users, it will match the second one, for "/" it will redirect to "/todos"
Also Redirect has from
and to
props. Your example has path
instead of from
Upvotes: 2