React history.push allow user to open in new tab
13,930
Solution 1
You can use <Link to='/conference'>Conference</Link>
to do this.
Solution 2
You should use Link
from react router
<Link to={`/conference`}>Conference</Link>
Related videos on Youtube
Author by
Cameron
Updated on May 21, 2022Comments
-
Cameron almost 2 years
Navigation between pages in my navbar is done using an onClick handler, rather than through hrefs. When doing this, I can't either middle click to open in a new tab or right click on the link and select open in new tab. I am using react-router-v4.
An example of a route.
<a onClick={() => this.props.history.push('/conference/')}>Conference</a>
Is there a way to allow this to happen in react or should I be using hrefs instead?
-
Useme Alehosaini over 3 yearsThank you and welcome @german-st, Can you provide an explanation for the answer, as it is very short