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

Pot*_*sys 4 reactjs gatsby

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

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

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

ksa*_*sav 12

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

import { navigate } from "@reach/router"  
Run Code Online (Sandbox Code Playgroud)
navigate(`/payment/${stripe_plan_id.id}`)
Run Code Online (Sandbox Code Playgroud)


Mah*_*aji 12

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

import { navigate } from "gatsby"  
Run Code Online (Sandbox Code Playgroud)
navigate(`/payment/${stripe_plan_id.id}`)
Run Code Online (Sandbox Code Playgroud)