Align multiple paths with responsive router v4
3 answers
Great answer. It also helps in the following scenario:
<Route path="/path/path1" component={MyComp} />
<Route path="/path/:subpath(path2|path3)" component={MyAnotherComp} />
Without (path2|path3)
both components MyComp
and MyAnotherComp
are installed if path /path/path2
.
PS. I would add it as a comment, but I would not have the right :).
+6
source to share
If you need to allow multiple match (different parameters), but also without a parameter - for example, matching URLs:
- / questions
- / questions / posted
- / questions / answered
This can be done with an optional parameter (note the question mark after the parenthesis)
<Route path="/questions/:tab(posted|answered)?" component={...} />
0
source to share