首页 > 解决方案 > react js将url布尔值传递给组件进行检测,检查时未定义

问题描述

我正在尝试通过 url 传递一个布尔值以供 react js 组件使用,但它一直未定义。我尝试了多个 url 组合,这是一个猜谜游戏。

我的布尔 url 属性的路线是

<Route path={"http://myurl.com/:showUserInfo"} component={myComponent}>

在渲染范围内的 myComponent

const test = this.props.match.showUserInfo 

测试总是未定义的。

我尝试了以下网址

http://myurl.com/:showUserInfo=false
http://myurl.com/showUserInfo=false
http://myurl.com/showUserInfo={false}

我想检测布尔标志,我可以得到值吗?

我又试了几次,但没有成功。任何帮助是极大的赞赏。谢谢

标签: reactjs

解决方案


请使用const test = this.props.match.params.showUserInfo从路线中读取。


推荐阅读