I want to disable Link
in some condition:
JavaScript
x
7
1
render() {
2
return (<li>{this.props.canClick ?
3
<Link to="/">Test</Link> :
4
<a>Test</a>}
5
</li>)
6
}
7
<Link>
must specify to
, so I can not disable <Link>
and I have to use <a>
Advertisement
Answer
You could just set set the link’s onClick property:
JavaScript
1
12
12
1
render () {
2
return(
3
<li>
4
{
5
this.props.notClickable
6
? <Link to="/" className="disabledCursor" onClick={ (event) => event.preventDefault() }>Link</Link>
7
: <Link to="/" className="notDisabled">Link</Link>
8
}
9
</li>
10
);
11
};
12
Then disable the hover effect via css using the cursor property.
JavaScript
1
4
1
.disabledCursor {
2
cursor: default;
3
}
4
I think that should do the trick?