使用 React Router 访问 URL 参数?

Accessing URL Parameters with React Router?

我通读了有关 URL React Router 参数的文档和教程,发现您应该 能够access the parameters in this.props.params。 this.props.params 在我的 render() 函数中未定义。我的 URL 当前看起来像这样: http://localhost:8000/?color=green 我正在尝试访问颜色值。这是您访问参数的方式还是有其他方法可以做到这一点?

要使用 React Router 访问 URL 参数,您可以使用 this.props.location.query.color,其中 color 是您要获取的 URL 参数的名称。