bhagi
bhagi

Reputation: 1

How to change domain name (entire url) in react-router-dom

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/

Upvotes: 0

Views: 2219

Answers (3)

Mohamadreza Kazemian
Mohamadreza Kazemian

Reputation: 301

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)

Upvotes: 1

Rodrigo Merlone
Rodrigo Merlone

Reputation: 397

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>

Upvotes: 3

Furkan Karakuzu
Furkan Karakuzu

Reputation: 93

You should use window.location.assign. For example

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

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

Upvotes: 0

Related Questions