react-router: How to disable a <Link>, if its active?

后端 未结 9 1010
谎友^
谎友^ 2020-12-14 06:10

How can I disable a in react-router, if its URL already active? E.g. if my URL wouldn\'t change on a click on I want to p

9条回答
  •  旧巷少年郎
    2020-12-14 06:19

    You can use CSS's pointer-events attribute. This will work with most of the browsers. For example your JS code:

    class Foo extends React.Component {
      render() {
        return (
          Bar
        );
      }
    }
    

    and CSS:

    .disabled-link {
      pointer-events: none;
    }
    

    Links:

    • pointer-events CSS property
    • How to disable HTML links

    The How to disable HTML links answer attached suggested using both disabled and pointer-events: none for maximum browser-support.

    a[disabled] {
        pointer-events: none;
    }
    

    Link to source: How to disable Link

提交回复
热议问题