question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<Redirect> + Page Transitions cause warning in the console

See original GitHub issue

Version

4.2.0

Test Case

https://codesandbox.io/s/13pykjo0wl

Steps to reproduce

  1. Navigate to /
  2. The router correctly redirects to /register, but shows a few warnings in the console: Warning: You tried to redirect to the same route you're currently on: "/register"

Expected Behavior

No warnings are shown

Actual Behavior

This is what I believe is happening.

Basically, in order to have the page transitions working correctly, the <Switch> needs to be provided with this.props.location, as it is immutable (unlike the history.location that is used by default). This guarantees that, during a transition to a new route, the page that is transitioning out still holds on the value of previous route.

Unfortunately, this seems to cause the warning when using <Redirect>: if the page that is transitioning out contains a Redirect, this page will keep triggering a route redirect, as its location will still hold on the value of old route.

You can have a look at this little demo to better understand the issue (have a look at the console logs)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ciampocommented, Apr 9, 2018

Thanks for pointing me to the auth workflow example. However, that example doesn’t have page transitions.

I made a new demo, based on your suggestions: https://codesandbox.io/s/6l4659qoor. I managed to get rid of the warnings, but at the cost of losing page transitions until the user is registered (try to click the button in the register page).

Is there anything better that I can do in order to have page transitions working while using <Redirect>?

1reaction
jmikrutcommented, Apr 20, 2018

@timdorr I don’t think your solution is universally acceptable.

We render redirects conditionally within a <Form> component based on responses returned by API calls. The <Redirect> therefore needs to be placed in the <Form> itself and we don’t have the luxury of simply moving the code.

What we’re working on now is trying to figure out how to render the <Redirect> only one time - but that’s easier said than done. Is there a reason why react-router does not include a way within the <Redirect> component to ensure that it only renders one time?

Read more comments on GitHub >

github_iconTop Results From Across the Web

<Redirect> + Page Transitions cause warning in the console
Well I think the issue is that transition-group re-renders the component (the route) that contains the <Redirect> with the various enter / exit ......
Read more >
React Router throwing redirect warnings with TransitionGroup
I am using React Router with React Transition Group to animate between routes. I have a problem when I use a <Redirect />...
Read more >
Causes of redirect errors and remedies - cocorograph
Redirect error: Google has one type of redirect: the redirect chain is too long, a redirect loop is occurring, the redirect URL eventually...
Read more >
Redirects and Google Search | Documentation
Redirecting URLs is the practice of resolving an existing URL to a different one, effectively telling your visitors and Google Search that a ......
Read more >
Open Redirect Warning - OutSystems 10 Documentation
The input parameter mentioned in the warning has a value that comes from the end-user input and that is susceptible to contain a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found