且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 React 中禁用链接的更简单方法?

更新时间:2023-11-28 22:12:34

你可以直接设置链接的 onClick 属性:

You could just set set the link's onClick property:

render () {
  return(
    <li> 
    { 
      this.props.notClickable
      ? <Link to="/" className="disabledCursor" onClick={ (event) => event.preventDefault() }>Link</Link>
      : <Link to="/" className="notDisabled">Link</Link>
    }
    </li>
  );
};

然后使用 cursor 属性通过 css 禁用悬停效果.

Then disable the hover effect via css using the cursor property.

.disabledCursor { 
  cursor: default;
}

我认为这应该可以解决问题?

I think that should do the trick?