Want to open a link in new tab in react router? Use the following script to open a link in new tab using reactjs.
1 2 3 4 | function openInNewTab(url) { var win = window.open(url, '_blank'); win.focus(); } |
Similar to the above example, but doesn’t error out if the window couldn’t be opened.
1 2 3 4 5 6 | function open(url) { const win = window.open(url, '_blank'); if (win != null) { win.focus(); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.