gatsby 中 this.props.history.push 的等价物是什么?

IT技术 reactjs gatsby
2021-05-07 14:30:50

我正在尝试做 this.props.history.push("/payment/" + stripe_plan_id)

Gastby 中 this.props.history.push 的等价物是什么?

我收到错误 TypeError: Cannot read property 'push' of undefined

2个回答

最佳答案不再有效但这确实有效:

import { navigate } from "gatsby"  
navigate(`/payment/${stripe_plan_id.id}`)

Gatsby 使用到达路由器请尝试以下操作:

import { navigate } from "@reach/router"  

navigate(`/payment/${stripe_plan_id.id}`)