Reputation: 11740
In React-router 1.0/2.0 one can access routing params as this.props.params
from a Route component - but there seems no supported way to access params from a component deeply contained in the above Route component.
The data sort of could be accessed through context.location
but this one throws a warning, stating this is deprecated.
Upvotes: 4
Views: 5238
Reputation: 159105
Starting in the latest version of React Router, all the context data has been deprecated in favor of this.context.router
:
Only an object named
router
is added to context. Accessingthis.context.history
,this.context.location
, andthis.context.route
are all deprecated. This new object contains the methods available fromhistory
(such aspush
,replace
) along withsetRouteLeaveHook
.
Unfortunately, this doesn't include the location
data, so you'll need to pass it yourself into child (non-route handler) components.
Upvotes: 8
Reputation: 2837
Per the 2.0.0 upgrade guide, you should pass params
or location
down to child components yourself as needed. See https://github.com/rackt/react-router/blob/master/upgrade-guides/v2.0.0.md#accessing-location.
Upvotes: 0