我试图在我的 URL 中传递参数,但我在阅读时遇到了问题。我正在使用反应路由器 v4。
网址: http://localhost:3000/reset?token=123 我正在尝试以这种方式阅读它:
<Route
path="/reset?token=:token"
component={Reset}/>
但这会打印空对象 console.log(this.props.match.params);
。奇怪的是我试图将问号更改为其他字符,看起来它解决了我的问题,但我还是想保留问号。
网址: http://localhost:3000/reset_token=123
<Route
path="/reset_token=:token"
component={Reset}/>
这已经有效 console.log(this.props.match.params);
。知道如何使问号也正确吗?对我来说真正重要的是继续使用没有任何外部库的 react-router。
干杯,丹尼尔
原文由 Dan Zawadzki 发布,翻译遵循 CC BY-SA 4.0 许可协议
我是如何解决这个问题的。
http://localhost:3000?token=mypetismissing