-
Notifications
You must be signed in to change notification settings - Fork 324
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
Comments
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? |
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 |
Possibly related issue: gatsbyjs/gatsby#7454 (comment) |
@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? |
Here's the temp fix I made in Gatsby for this gatsbyjs/gatsby#7758 |
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.
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. |
gatsbyjs/gatsby/issues/5656
The text was updated successfully, but these errors were encountered: