In order to prevent HTML default link from opening new page, you simply code:
<a href="#" onclick="console.log('I get clicked.'); return false">
Click here
</a>
In react, you need to do it with preventDefault
.
// React
function LinkMe() {
function handleClick(e) {
e.preventDefault();
console.log('I get clicked');
}
return (
<a href="#" onClick={handleClick}>
Click here
</a>
);
}