0

If I am in http://localhost:3000/Authpage I want to redirect to new URL http://www.example.com/

Usehostory() -> histor.push() is appending new url to old url. http://localhost:3000/Authpage/http://www.example.com/

But I need new location something like below http://www.example.com/

bhagi
  • 1
  • 2

3 Answers3

3

You can have a look at this thread here for an answer.

To summarize it, in your event handler you can add

const eventHandler = () => {
    window.location.assign('http://www.example.com/')
}

However, the way I see it, it's just easier to create a simple regular HTML <a> tag:

<a href='http://www.example.com/'>click to redirect</a>
Rodrigo Merlone
  • 352
  • 2
  • 7
1

you have 2 options use tag to redirect the user into a new web page. or use one of the javascript methods like window.open("yourUrl.com") but be careful when you are using javascript methods to redirect the user because the safari browser would not let you use some of them( because of some security filters)

0

You should use window.location.assign. For example

 handleClick() {
    window.location.assign('http://www.example.com/');
  }

  render() {
    return (
      <button onClick={this.handleClick.bind(this)} />
    );
  }`