react-router-dom: 4.1.1
react-router-config: ^1.0.0-beta.4
https://codesandbox.io/s/j14yvr4rr9
navigate to 'organisation info'
params.organisationGuid in Home component is 'some-organisation-guid'
params.organisationGuid in Home component is 'undefined'
This is expected. params are not global, so they're not available to the ancestor components in the tree where the match occurs.
Is there a way to get params from children?
@timdorr I really believe that this should be considered a bug. Not having the params available as a global object seems like a total anti-pattern, considering the URL is available globally. If I have a breadcrumbs component that exists across the entire application and it needs to be able to fetch data on occasion, I have to parse the URL manually when IMO it should inherently be possible while using the router.
That is logically impossible. You can have <Route>s anywhere in your tree, with their own arbitrary params. There is not one canonical representation of the current <Route> and therefore the current match, only what is closest in the ancestor chain. We no longer have the concept of a central route config.
@goodbomb Exactly. Because of this decision I probably won't be available to upgrade my application from v3 to v4, since it's heavily dependent on params being accessible in various components.
Only way is to check various matchPath for every possible param everytime url changes and manually store it somewhere... But I fail to see how v4 is an upgrade.
@timdorr Please developers reconsider this. For multiple matches, "match" can be an array of objects, not?
It's not a matter of us deciding otherwise. It's simply not possible. Routes exist at any point in a tree, including underneath where you need to access those params.
You can use react-router-config to define a top-level route config and use that down the tree.
Most helpful comment
@timdorr I really believe that this should be considered a bug. Not having the params available as a global object seems like a total anti-pattern, considering the URL is available globally. If I have a breadcrumbs component that exists across the entire application and it needs to be able to fetch data on occasion, I have to parse the URL manually when IMO it should inherently be possible while using the router.