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 have an application where my route reacts to changes to the props.match object passed as part of the route props. When my route is cached, props.match become unavailable and the route re-renders in the background. When the route is restored, it must re-render, which has some unwanted side-effects for my application.
Steps to reproduce
Using the following application:
importReactfrom'react';import{HashRouterasRouter,Link}from'react-router-dom';import{CacheSwitch,CacheRoute,useDidCache,useDidRecover,}from'react-router-cache-route';constRoute=function(props){console.log(`Route ${props.number} rendered:`,props.match);useDidCache(()=>console.log(`Route ${props.number} cached`));useDidRecover(()=>console.log(`Route ${props.number} recovered`));returnprops.children;};constApp=function(){return(<Router><CacheSwitch><CacheRouteexactpath="/route1"render={(renderProps)=>(<Route{...renderProps}number="1"><h1>Route 1</h1><Linkto="/route2">Go to route 2</Link></Route>)}/><CacheRouteexactpath="/route2"render={(renderProps)=>(<Route{...renderProps}number="2"><h1>Route 2</h1><Linkto="/route1">Go to route 1</Link></Route>)}/></CacheSwitch></Router>);};exportdefaultApp;
Navigate to /route1.
Click "Go to route 2", observe the console.
You will see that route 1 first renders, props.match is available to it:
looks like you need to rely on props.match to do something?
which version of cache-route you are using? Can the previous version work?
If the old version takes effect, it may be a recent change that has caused the problem, you can try to use the latest version 1.12.8 to see if the problem is fixed
If not, you may need to deal with props.match yourself.
Description
I have an application where my route reacts to changes to the
props.match
object passed as part of the route props. When my route is cached,props.match
become unavailable and the route re-renders in the background. When the route is restored, it must re-render, which has some unwanted side-effects for my application.Steps to reproduce
Using the following application:
/route1
.You will see that route 1 first renders,
props.match
is available to it:However, when route 2 is loaded, route 1 re-renders with
props.match
unavailable:You will see that route 1 recovers and
props.match
is available once again:The text was updated successfully, but these errors were encountered: