Today, We want to share with you open link in new tab react.In this post we will show you How to Open URL in New Tab using ReactJS, hear for react open link in new tab programmatically we will give you demo and example for implement.In this post, we will learn about External Links in New Window / New Tab with an example.
There are the Following The simple About When to open a link in new tab by default? Full Information With Example and source code.
As I will cover this Post with live Working example to develop react open new tab on button click, so the How to open menu links in a new tab or window is used for this example is following below.
App.js
<Link to="/home">Homepage</Link>
app.js
import { BrowserRouter, Route, } from 'react-router-dom'
import UserList from './path/to/UserListComponent'
class App extends Component {
...
render() {
return (
<BrowserRouter>
...
<Route path="/users" component={UserList}/>
...
</BrowserRouter>
)
}
}
the component receives history object as a prop
this.props.history.push("/coronavirus-list");
Using withRouter
import { withRouter } from "react-router-dom";
export default withRouter(yourComponent);
I hope you get an idea about react open new tab programmatically.