ReactJS – How to access routing parameters from components other than router components

In React-router 1.0/2.0, the route parameters this.props.params can be accessed from the Route component-but there seems to be no supported method to access from the components deeply contained in the Route component above Parameters.

Data sorting can be accessed through context.location, but this will throw a warning that this has been deprecated.

Starting in the latest version of React Router, all context data has been deprecated to support this.context.router:

< p>

Only an object named router is added to context. Accessing this.context.history, this.context. location, and this.context.route are all deprecated. This new object contains the methods available from history (such as push , replace) along with setRouteLeaveHook.

Unfortunately, this does not include location data, so you need to pass it yourself to Child (non-route handler) component.

In React-router 1.0/2.0, the route parameters this.props.params can be accessed from the Route component-but there seems to be no support The method accesses the parameters from the components deeply contained in the Route component above.

Data sorting can be accessed through context.location, but this will throw a warning that this has been deprecated.< /p>

From in the latest Starting with version of React Router, all context data has been deprecated to support this.context.router:

Only an object named router is added to context. Accessing this.context.history, this.context.location, and this.context.route are all deprecated. This new object contains the methods available from history (such as push, replace) along with setRouteLeaveHook .

Unfortunately, this does not include location data, so you need to pass it yourself to the child (non-route handler) component.

Leave a Comment

Your email address will not be published.