![]() ![]() There are other ways to solve this but hopefully this gives you a little bit of an understanding of what is happening inside of React Router. We have a parent route that is matching paths for child rendered routes and doing some data loading. It's only providing the match information for the path we specified on the route which is /profile without any ID. Well if we have this setup, and then visit /profile/1 our App component would look like this. But hypothetically speaking maybe you want to visit /profile and also match /profile/:profileId and pass through to the same component that is holding onto state. We could theoretically fix this by passing in /profile/:profileId and only rendering if we have an id match. If we take a look at this top level route, we can see that we want anything that matches /profile to pass on through to our App component. We can use the internal mechanisms of React Router to match any route we want. There may be a time in your application when you need to compare the previous route id to the current route id to load data or respond in some way.
0 Comments
Leave a Reply. |