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/

3 Answers 3

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>

Sign up to request clarification or add additional context in comments.

Comments

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)

Comments

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)} />
    );
  }`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.