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>
Share:
13,930

Related videos on Youtube

Cameron
Author by

Cameron

Updated on May 21, 2022

Comments

  • Cameron
    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
    Useme Alehosaini over 3 years
    Thank you and welcome @german-st, Can you provide an explanation for the answer, as it is very short