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

add push/pop to history #119

Closed
ryanflorence opened this issue Aug 8, 2018 · 6 comments
Closed

add push/pop to history #119

ryanflorence opened this issue Aug 8, 2018 · 6 comments

Comments

@ryanflorence
Copy link
Member

gatsbyjs/gatsby/issues/5656

@ryanflorence ryanflorence changed the title add push/pop to locations add push/pop to history Aug 8, 2018
@sergical
Copy link

Would love to see this type of API enabled. I am building an application that is targeting users with disabilities. The context it would be used in, as an example, after submitting a form, I'd want to redirect a user to a different page, so

handleFormSubmit = e => {
  e.preventDefault();
  this.submitForm(data, (err, res) => {
    if (!err) {
      history.push('/profile');
      // I don't think I can use the Redirect component from the API in this case
    }
  })
}

Or is there a better pattern I should be implementing?

@GainorB
Copy link

GainorB commented Aug 19, 2018

import { navigate } from "@reach/router"

handleFormSubmit = e => {
  e.preventDefault();
  this.submitForm(data, (err, res) => {
    if (!err) {
      navigate('/profile')
    }
  })
}

Did you try using the navigate? Seems like your use case is perfect for it

@DylanVann
Copy link

Possibly related issue: gatsbyjs/gatsby#7454 (comment)

@thebigredgeek
Copy link

@ryanflorence ^ Yeah that's definitely a big use case for this, making sure we allow for standard browser behavior when people click links. As you mentioned on gatsbyjs/gatsby#5656, we could technically work around this with a hash table but it seems like this is something the routing component provides. Thoughts?

@KyleAMathews
Copy link

Here's the temp fix I made in Gatsby for this gatsbyjs/gatsby#7758

DSchau pushed a commit to gatsbyjs/gatsby that referenced this issue Sep 13, 2018
Reach Router has it.
React Router has it.
Probably any other router out there has it too.

A need arose for me to have such functionality, was surprised it doesn't exist, so, I made one.
The need for me is opening/closing modals, not really looking for them to be stored in history.

I'm not sure if this won't have to be changed once reach/router#119 lands, but in the same fashion as scroll behavior has been fixed for now, made the quick-fix here.
@ryanflorence
Copy link
Member Author

Added, but I encourage people to track location keys instead--an unseen key is PUSH, everything else is pop.

Relying only on "POP" is potentially broken since users can pop to any spot in the history stack (click and hold the back/forward button and choose something down the list). You'll want to inspect the keys to see how far back or forward the user went and act on that delta rather than just a naive pop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants