I'm a bit stuck with the route component. Imagine I have this two Routes with their own path:
<Route path='/person/add' exact component={PersonForm}/>
<Route path='/person/:id' exact component={PersonView}/>
/person/add should show a form where I can create a new Person
/person/:id should show a person with the given id.
The problem >> If I navigate to /person/add it will also show the component of /person/:id because the string "add" is valid for ":id".
Is there a way I can avoid this? For example by telling that :id should be a number?
Found a possible solution: You can use Switch around the routes. Then it will only match on the first one that matches.
<Switch>
<Route path='/person/add' exact component={PersonForm}/>
<Route path='/person/:id' exact component={PersonView}/>
</Switch>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With