I have a component called <TaskView>
that renders some info about a specific task. My tasks are nested so that I would be able to navigate like so /task1/task1-1/task1-1-1...
and so on for N (indefinitely).
How should I write a path that would resolve this url ?
To write a path for level 1 nested I would do: <Route path="/task/:p1" component={taskView} />
, for level 2 I would do <Route path="/task/:p1/:p2" component={taskView} />
I don't know how deep the task structure would be, so how would I write a path for an undefined number of parameters ?
Asked
Active
Viewed 48 times
0

zaliar
- 1
- 1
1 Answers
0
ReactRouter has a notion of non exact matches. It will attempt to find the best match so you don't need to define all these subroutes to mount the same components.
React : difference between <Route exact path="/" /> and <Route path="/" />
So actually you should be able to do
<Route path="/task/:p1" component={taskView} />
just fine.

Pandelis
- 1,854
- 13
- 20
-
1I also need to know which task needs to be displayed, so I need at least the last element or parameter. How could I get that properly ? A way to do it would be ```location.pathname.split('/')``` and then get the last element, but that seems a little bit hacky. – zaliar Jan 22 '20 at 10:52