盖茨比中的this.props.history.push等效于什么?

时间:2019-11-03 05:09:52

标签: reactjs gatsby

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

Gastby中的this.props.history.push等效于什么?

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

2 个答案:

答案 0 :(得分:2)

盖茨比使用reach router。请尝试以下操作:

import { navigate } from "@reach/router"  

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

答案 1 :(得分:1)

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

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