9951 explained code solutions for 126 technologies


reactjsHow do I open a URL in ReactJS?


To open a URL in ReactJS, you can use the window.open() method. This method takes two parameters: a URL string and a window name.

The following example code opens the URL https://www.example.com in a new window named exampleWindow:

window.open('https://www.example.com', 'exampleWindow');

No output is produced.

The code consists of two parts:

  1. The window.open() method, which is used to open a new window for a specified URL.
  2. The parameters of the window.open() method, which are the URL and the window name.

For more information on the window.open() method, see the MDN Documentation.

Edit this code on GitHub