What is the proper ordering of routes in routes.js? #8332
-
I just discovered that the order matters when declaring routes. If the order is wrong, the component which is mapped to the route won't render. What is the proper order for routes? Is there documentation present? This works: <Switch>
<Route exact path="/">
<App />
</Route>
<Route path="/persons/add">
<PersonFormContainer action="Create" />
</Route>
<Route path="/persons/edit/:id">
<PersonFormContainer action="Edit" />
</Route>
<Route path="/persons/:id">
<PersonDetailsContainer />
</Route>
<Route path="/persons">
<PersonsListContainer />
</Route>
</Switch>
); but this doesn't <Switch>
<Route path="/persons/edit/:id">
<PersonFormContainer action="Edit" />
</Route>
<Route exact path="/">
<App />
</Route>
<Route path="/persons/add">
<PersonFormContainer action="Create" />
</Route>
<Route path="/persons/:id">
<PersonDetailsContainer />
</Route>
<Route path="/persons">
<PersonsListContainer />
</Route>
</Switch> |
Beta Was this translation helpful? Give feedback.
Answered by
MeiKatz
Nov 14, 2021
Replies: 1 comment 2 replies
-
In RRv5 routes are matched from top to bottom: if a path matches the matching stops and the first matching route wins. |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
mjackson
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In RRv5 routes are matched from top to bottom: if a path matches the matching stops and the first matching route wins.