React-router Link 组件防止子节点默认
React-router Link component prevent default for child
我正在尝试将 onClick
处理程序放在 Link
子项上。问题是它没有触发,因为 Link's
transition
方法。有没有 preventDefault
左右?这是 jquery 世界中的示例
how to stop redirection of parent href tag when clicked on child div?
来自 onClick
文档:
A custom handler for the click event. Works just like a handler on an a
tag - calling e.preventDefault()
will prevent the transition from firing, while e.stopPropagation()
will prevent the event from bubbling.
所以你应该可以使用 e.preventDefault
https://github.com/rackt/react-router/blob/master/docs/API.md#onclicke
我正在尝试将 onClick
处理程序放在 Link
子项上。问题是它没有触发,因为 Link's
transition
方法。有没有 preventDefault
左右?这是 jquery 世界中的示例
how to stop redirection of parent href tag when clicked on child div?
来自 onClick
文档:
A custom handler for the click event. Works just like a handler on an
a
tag - callinge.preventDefault()
will prevent the transition from firing, whilee.stopPropagation()
will prevent the event from bubbling.
所以你应该可以使用 e.preventDefault
https://github.com/rackt/react-router/blob/master/docs/API.md#onclicke