I have a React component that is clickable as a whole, but also contains buttons inside.
So something like
...
<
Nesting anchor tags (which is what <Link />
transpiles to) is forbidden in HTML. Even if you get the desired result, it is only because your browser is clever and has its own work-arounds. However, that behavior cannot be guaranteed across all browsers and platforms.
How seriously should I take this?
As per the above, I'd say quite seriously.
What would be the workaround?
The following isn't a workaround, but what I consider to be the "proper" implementation.
I'd programatically implement the navigation for the wrapping element and use the <Link />
for the buttons. So something like:
navigate = () => {
//push "path1" to history
}
render() {
return(
<div onClick={this.navigate}>
<Link to="path2">Some button</Link>
<Link to="path3">Some button</Link>
</div>
);
}
For more info about programatically navigating in React Router see one of the links below: