I'm trying to do this.props.history.push("/payment/" + stripe_plan_id)
What is the equivalent of this.props.history.push in Gastby?
I get the error TypeError: Cannot read property 'push' of undefined
For internal navigation, Gatsby includes a built-in <Link> component for creating links between internal pages as well as a navigate function for programmatic navigation. The component is a wrapper around @reach/router's Link component that adds useful enhancements specific to Gatsby.
React is a library that is meant to provide a certain set of core functionality for developers to leverage. It is intended to be lightweight and broadly applicable. Gatsby, on the other hand, is a static progressive web app (PWA) generator that offers code and data splitting out of the box.
You can add this as a siteURL property on siteMetadata in gatsby-config. js . Once you have added siteURL , you can form the absolute URL of the current page by retrieving siteURL and concatenating it with the current path from location . Note that the path starts with a slash; siteURL must therefore not end in one.
Routes can be created in three ways: By creating React components in src/pages. By using the File System Route API to programmatically create pages from GraphQL and to create client-only routes. By implementing the API createPages in your site's gatsby-node.
The top answer doesn't work anymore But this does work :
import { navigate } from "gatsby"
navigate(`/payment/${stripe_plan_id.id}`)
Gatsby uses reach router. Try the following:
import { navigate } from "@reach/router"
navigate(`/payment/${stripe_plan_id.id}`)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With