reactjs - 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}
我想检测布尔标志,我可以得到值吗?
我又试了几次,但没有成功。任何帮助是极大的赞赏。谢谢
解决方案
请使用const test = this.props.match.params.showUserInfo
从路线中读取。
推荐阅读
- typescript - 如何检查字符串 | 数字在数组中,可能是不同的类型?
- node.js - HandsonTable:无法通过对齐和合并检索数据
- c++ - 如何解决以下问题?致命错误 C1083:无法打开包含文件:'stdlib.h':没有这样的文件或目录
- php - 在 Prestashop 1.7 的结帐中添加字段并处理值
- python - 如何有效且非破坏性地对地理执行着色器分配?
- python - 如何通过对一列中的每一行执行 api 调用来更新 MySQL 数据库列
- python - 如何按列提取 pd 行,并左移 2 列
- html - 如何在在线平台(Wix/Squarespace)上以 xml/x3d 显示 X3D 对象?
- javascript - 检查是否在 Javascript 运行时调用/执行了特定方法
- mysql - MySQL 更新和加入