Triggering a callback when changing a request in a reaction router

I am looking for a swap solution in routing with a jet router and reducer.

React-router does not start the callback in onEnter, unless the request changes, the method is Router.rundeprecated, so I'm a bit puzzled. Is there anything else that can be done besides manually subscribing to location.change or using lifecycle reactive hooks, for example willReceiveProps?

+4
source share
2 answers

In the comments, the only click of a button <Router>is onUpdate. You can also intercept request parameters using a custom RoutingContext, but we are not currently considering this open API.

We want to add a better solution for this use case in the future, but the approaches described are the only ones available for release 1.0.0.

+5
source

For those using v2.0 / v3.0, you can use hook onChangeto respond to requests.

<Route
  component={...}
  path="..."
  onChange={(nextState, replace, callback) => {
    // Do something in response to a query change...
  }}
/>

https://github.com/ReactTraining/react-router/blob/master/docs/API.md#onchangeprevstate-nextstate-replace-callback

+1
source

Source: https://habr.com/ru/post/1615574/


All Articles