React-router: The location of the <Redirect/> will result in error( Maximum update depth exceeded)

Created on 16 May 2019  路  5Comments  路  Source: ReactTraining/react-router

Version

**"react": "^16.8.6","react-dom": "^16.8.6","react-router-dom": "^5.0.0",

Test Case

correct one
incorrect one

Just look the example.js

Steps to reproduce

Just change the loacation of line 28 and line 29 in example.js , the error will occur.

Expected Behavior

The demo in official document about Redirect is actually wrong.The two sentences in the picture need to be exchanged, otherwise an error will be reported(Maximum update depth exceeded).
image
in my project throw this error:
image

Actual Behavior

Throw an error, Maximum update depth exceeded. I think if this not an error, The docs need to update, And this order needs to be emphasized in the docs, otherwise it is difficult to understand

Most helpful comment

Yep, this is already fixed by #6673. I hope to have a release out soon.

All 5 comments

That's definitely not the expected behaviour. I will have a look and will fix this.

I'm reasonably sure that this is another manifestation of #6673 and should be fixed by 5.0.1.

In the meantime:

@WormGirl You run into this bug, because your Redirect from always matches, because /users/profile matches for /user/:id.

The easiest fix to to simply add 'exact' to the Redirect:

<Redirect from="/" exact to="/about" />

See this fork of your codesandbox:

https://codesandbox.io/s/react-router-basic-cro61

Yep, this is already fixed by #6673. I hope to have a release out soon.

<Redirect exact /> still triggers the recursion if the from route is inside an inexact match. For example, when redirecting from a root path to a deeper path (/me -> /me/home)

EDIT: I didn't test the master branch, this was a comment about the workaround suggested for 5.0.0

<Redirect exact /> still triggers the recursion if the from route is inside an inexact match. For example, when redirecting from a root path to a deeper path (/me -> /me/home)

EDIT: I didn't test the master branch, this was a comment about the workaround suggested for 5.0.0

As @StringEpsilon said, this bug will be fixed in 5.0.1

Was this page helpful?
0 / 5 - 0 ratings