You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I love the concept of redial and gave it a whirl with react-router. However, I'm not using server rendering.
I went through some loops to get it working the way I prefer. My use case is that I want a callback ('fetch') to fire whenever a route is visited or "refreshed" by clicking the link for the current route.
In your examples, this is accomplished by using history.listen(). The issue with this approach is that it will not fire on the initial page load. Also, using match on the client causes onEnter callbacks to fire multiple times, which is not good.
My solution was to do something like this:
consttriggerRedial=(nextState,replace)=>{constlocals={path: nextState.location.pathname,query: nextState.location.query,params: nextState.params,dispatch: dispatch,// Accessed vial closure};constcomponents=nextState.routes.map(c=>c.component);trigger('fetch',components,locals);};// ..snip..<Routepath='/'component={Root}onEnter={triggerRedial}onChange={(prev, ...rest)=>triggerRedial(...rest)}>{/* All children routes */}</Route>
onEnter does what you would expect, and onChange handles the case of when the existing route changes within itself. This doesn't cause duplicate firings, and seems to work great.
Should we consider updating the docs with this example?
The text was updated successfully, but these errors were encountered:
I love the concept of redial and gave it a whirl with react-router. However, I'm not using server rendering.
I went through some loops to get it working the way I prefer. My use case is that I want a callback ('fetch') to fire whenever a route is visited or "refreshed" by clicking the link for the current route.
In your examples, this is accomplished by using
history.listen()
. The issue with this approach is that it will not fire on the initial page load. Also, usingmatch
on the client causesonEnter
callbacks to fire multiple times, which is not good.My solution was to do something like this:
onEnter
does what you would expect, andonChange
handles the case of when the existing route changes within itself. This doesn't cause duplicate firings, and seems to work great.Should we consider updating the docs with this example?
The text was updated successfully, but these errors were encountered: