Open nomyfan opened 1 year ago
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
Switch
Go
CacheSwitch
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).
React.Children.forEach
React.Children.map
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.tsxGo
button, then the component underCacheSwitch
will be re-mounted.Go
button, the component underCacheSwitch
will be re-mounted.