react-router-cache-route icon indicating copy to clipboard operation
react-router-cache-route copied to clipboard

`CacheSwitch` re-mount the same component if path changes

Open nomyfan opened this issue 2 years ago • 1 comments

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 under CacheSwitch will be re-mounted.
  • Clear the input, and click Go button, the component under CacheSwitch will be re-mounted.

nomyfan avatar Dec 11 '22 14:12 nomyfan

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).

nomyfan avatar Dec 11 '22 16:12 nomyfan