javascript - ReactJS + react 路由器 : How to disable link from React-Router's <Link>?

标签 javascript html css reactjs react-router

使用 React-Router 的链接,我有一个像这样的设置:

<Link to={...}>{this.props.live? "Live": "Not Live"}</Link>

如果 this.props.live被传入,我想简单地显示一个文本“实时”,它将指向一个新页面。如果this.props.live未传入,想要显示文本“Not Live”但从中删除超链接/停用/禁用它。

有可能吗?我试过 <div style={{pointerEvents: "none"}}>Not Live</div> ,但不起作用。

将投票并接受答案。谢谢!

最佳答案

你应该这样做:

let component;

component=this.props.live? <Link to={...}> Live </Link>: <div> Not Live </div>
 render() {
    {component}
  }

干杯:)

关于javascript - ReactJS + react 路由器 : How to disable link from React-Router's <Link>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41600609/

相关文章:

php - 在 img 标签中使用 php 获取文件 url 时出现问题

css - 来自 Twitter API 的图像呈现为 1px x 1px

javascript - 如何在 TR 元素上设置 name 和 id?

javascript - 捕获太长的表单提交

html - 为什么我的媒体查询不起作用?

javascript - 单元格模板中的 Angularjs 指令 ng-hide 不绑定(bind)网格数据的更改

javascript - 隐藏仅适用于 ios 平板电脑的下载按钮纵向和横向模式

javascript - 指定选择器时,为什么 jQuery .index() 方法仅适用于集合中的第一个元素?

javascript - 简单的 JavaScript 函数来持续改变按钮 onclick 的状态?

javascript - 事件页面链接失败