Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<Redirect> renders blank page #5047

Closed
evoyy opened this issue Apr 27, 2017 · 5 comments
Closed

<Redirect> renders blank page #5047

evoyy opened this issue Apr 27, 2017 · 5 comments

Comments

@evoyy
Copy link

evoyy commented Apr 27, 2017

Version 4.1.1

When navigating to /settings I want it to redirect to /settings/profile

I expected this to work

<Switch>
    <Redirect from="/settings" to="/settings/profile" />
    <Route path="/settings" component={Settings} />
</Switch>

The URL in the address bar is updated but nothing is rendered.

Instead I have to do this:

<Switch>
    <Route exact path="/settings" render={() => {
        return <Redirect to="/settings/profile" />
    }} />
    <Route path="/settings" component={Settings} />
</Switch>

Is this expected behaviour?

@evoyy
Copy link
Author

evoyy commented Apr 27, 2017

Related to #5003 ?

@oliverasistemas
Copy link

Did you try using exact on the redirect route?

@timdorr
Copy link
Member

timdorr commented Apr 27, 2017

Yeah, that's what is happening here. Your Redirect is loosely matching the pathname, so you're getting into a loop.

@timdorr timdorr closed this as completed Apr 27, 2017
@evoyy
Copy link
Author

evoyy commented Apr 27, 2017

That works, thanks. I didn't think that Redirect accepted an exact prop, but I just saw this:

When you include a <Redirect> in a <Switch>, it can use any of the <Route>'s location matching props: path, exact, and strict. from is just an alias for the path prop.

@alexilyaev
Copy link
Contributor

@timdorr I think that line in the doc that mentions we can use any props of Route on our Redirect should also be under the Redirect section of the doc:
https://reacttraining.com/react-router/web/api/Redirect

I completely missed it and wondered why things didn't work, and only later found this issue and the mentioned line.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants