-1

Hallo I am new to React and here.

I have questiona about redirect to an URL in React. I am wondering if I can make React page redirect to another URL like www.google.com I did it like .

<a href='http://localhost:8000/api?issuer=ideal_KNABNL2H'>Go to Pay</a> 
<button onclick="window.location.href='http://www.google.com'">

But it doen't work at React. Can it be done in react-router? I have read its doc, still don't know how to make it.

Cheng Ma
  • 1
  • 1
  • 1

4 Answers4

2

You don't need react for this :)

<a href="https://www.google.com/"><button>Visit google</button></a>
Sergej
  • 2,030
  • 1
  • 18
  • 28
1

This works well for me

<button onClick={() => window.open( 'http://www.google.com')} >google</button>
Steve Bohmbach
  • 327
  • 1
  • 11
0
<a href={https://www.google.com}>Google!</a>

Make sure you just include "https://" before the website. I'm also new to react here, and was having trouble when I wrote only "www.google.com". It was adding that to the end of my URL instead of redirecting to Google's website.

tdy
  • 36,675
  • 19
  • 86
  • 83
Asanyth
  • 25
  • 4
-2
<MyLink link="http://www.google.com" title="Google"/>

If it is to redirect to another page, enter http, but if it is to access screen in the project it is used React Router

npm install react-router-dom