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

StaticRouter: retain location.state [WiP] #5935

Closed
wants to merge 1 commit into from

Conversation

wmertens
Copy link
Contributor

When redirecting, location.state is lost. This can be useful to pass information like state: {permanent: true} which could result in HTTP 301 response.

Spiritual continuation of #5930; no tests yet, just a proposal.

When redirecting, `location.state` is lost. This can be useful to pass information like `state: {permanent: true}` which could result in HTTP 301 response
Copy link
Member

@timdorr timdorr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems sensible, but we need tests.

@pshrmn
Copy link
Contributor

pshrmn commented Feb 14, 2018

I believe #5722 would supersede this (it removes normalizeLocation and uses history.createLocation instead).

@timdorr
Copy link
Member

timdorr commented Feb 14, 2018

Yes, it would. But it also doesn't have tests for location.state 😄

@mjackson
Copy link
Member

Can you please show some a small sample app where you found this useful, @wmertens? It would help me to get inside your head and see why you think this is useful.

@wmertens
Copy link
Contributor Author

@mjackson there are 2 main cases:

  • differentiate between 301 and 302 redirects:
    • For SEO, I have been told that it's better that pages be redirected 301 to their canonical equivalent. This also makes browsers remember and directly ask for the canonical URL.
    • However, for e.g. redirecting after logout, 302 should be used, otherwise you can't visit the originating URL any more :)
  • mark a page as missing (404):
    • Search engines have to know when a page has no real content. For example if you link to a wrong url on a blog, Google needs to know that that is a 404, but regular visitors should not have their url changed to /404.
    • Right now I'm working around this by not redirecting when the url is /404, but it's cleaner to just pass notFound in the state.

Anyway, I do believe that the new version with #5722 should fix this, but I didn't get around to trying it yet.

@wmertens
Copy link
Contributor Author

Closing this PR (at least until I got to test the new version), but would be interested in other approaches to those use cases @mjackson!

@wmertens wmertens closed this Mar 30, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 2018
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.

None yet

4 participants