remix-run / react-router

Declarative routing for React
https://reactrouter.com
MIT License
52.95k stars 10.26k forks source link

Full rerender triggered when navigate to route A that redirect to current route B #7080

Closed hackwaly closed 4 years ago

hackwaly commented 4 years ago

Version

react-router-dom@5.1.2

Test Case

https://codesandbox.io/s/react-router-u0yte

Steps to reproduce

  1. Open devtools, inspect the "Home" link element.
  2. Click "Home" link

Actual Behavior

You will see the page is not change, but devtools lose selection of "Home" link. If you use react devtools, You will found that the whole about component did full render again after click "Home" link. I guess reason is there's a temporary frame of switch component before the final render. It renders nothing, So react can't reuse about component after that.

Expected Behavior

No rerender occurs

timdorr commented 4 years ago

This is just how React works. We're unmounting that component for the redirect and then remounting it after we get redirected.