Skip to content

Conversation

levibotelho
Copy link

I needed to handle async routes with potential redirects in the render method on the client, so I figured I would add it to the doc. Not sure if this is the right way to go about it, but if it is it'd probably be good to have it in the documentation if it is.

@taion
Copy link
Contributor

taion commented May 14, 2016

Why would you have a redirect on the client but not on the server?

@levibotelho
Copy link
Author

levibotelho commented May 14, 2016

If a non-authed user navigates through my app to certain pages but isn't logged in I redirect them in an onEnter callback to a login page. I do have a redirect on the server but this is entirely client-side.

@taion
Copy link
Contributor

taion commented May 14, 2016

Yes, but don't you do that on the server render anyway?

@levibotelho
Copy link
Author

Maybe I'm missing something, but here goes.

On my server I handle redirects as per the doc, however in my app if an unauthenticated user clicks a Link which leads them to a page that requires authentication, an onEnter hook will call replace to redirect the user to a sign in page. In this case, the match method is invoked on the client end as per the doc, however renderProps is undefined and redirectLocation is provided so I need to handle that accordingly. At no point in this workflow is my server code invoked.

Does that make sense, or is my implementation incorrect?

@taion
Copy link
Contributor

taion commented May 16, 2016

That match only runs on the initial render. Everything else is handled within <Router>.

@taion
Copy link
Contributor

taion commented May 20, 2016

Any update here? I still don't understand how you'd hit a redirect on the initial client render.

@levibotelho
Copy link
Author

Sorry for the late response I've been travelling.

Indeed you're correct, I understand the confusion. In my case I do not prerender pages which require authentication to view, as the Node instance which serves my frontend does not know whether a user is authed. As such it's the frontend itself which decides whether to redirect for these pages.

As this is a bit of a weird case maybe it's best not to complicate the doc with it.

@taion
Copy link
Contributor

taion commented May 21, 2016

That's my thinking, yes. Thanks.

@taion taion closed this May 21, 2016
@levibotelho levibotelho deleted the add-redirect-to-async-doc branch May 24, 2016 22:08
@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

Successfully merging this pull request may close these issues.

2 participants