react-router-cache-route
react-router-cache-route copied to clipboard
`CacheSwitch` re-mount the same component if path changes
In Switch
, the component will not be re-mounted even if the path changed.
Here's a demo to reproduce.
https://stackblitz.com/edit/vitejs-vite-4923pg?file=src/App.tsx
- Type something in the input, click
Go
button, then the component underCacheSwitch
will be re-mounted. - Clear the input, and click
Go
button, the component underCacheSwitch
will be re-mounted.
Switch
uses React.Children.forEach
to capture the matching element, while CacheSwitch
uses React.Children.map
to return an array(React assigns keys to each child in the array).