react opening new pages code example
Example 1: how to open a new tab in react
const openInNewTab = (url) => {
const newWindow = window.open(url, '_blank', 'noopener,noreferrer')
if (newWindow) newWindow.opener = null
}
onClick={() => openInNewTab('https://stackoverflow.com')}
Example 2: react link to another page
import { Link } from 'react-router-dom';
classAppextendsComponent {
render() {
return (
<div class="container">
<nav>
<Link to="/">Home</Link>
<Link to="/dashboard">Dashboard</Link>
</nav>
<Route
path="/"
component={HomeComponent}
exact
/>
<Route
path="/dashboard"
component={DashboardComponent}
/>
</div>
);
}
}