close

React button onClick redirect page

Today We are Going To Solve React button onClick redirect page in reactjs. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.

How to Fix React button onClick redirect page Error?

  1. How to Fix React button onClick redirect page Error?

    To Fix React button onClick redirect page Error just Use a link styled as a button. You have to just use a link styled as a button just like given in the below code. Try this.
    <Link to="/signup" className="btn btn-primary">Sign up</Link>

  2. React button onClick redirect page

    To Fix React button onClick redirect page Error just Use the command. Just use the below command. It's a very easy and simple method. Try it. onClick={event => window.location.href='/your-href'}

You have to just use a link styled as a button just like given in the below code. Try this.

<Link to="/signup" className="btn btn-primary">Sign up</Link>

Solution 2 : Use the command

Just use the below command. It’s a very easy and simple method. Try it.

onClick={event =>  window.location.href='/your-href'}

To solve this error you have to import {Link} from “react-router-dom”; And just hyperlink instead of using a function.

import {Link} from "react-router-dom";

<Button>
   <Link to="/yourRoute">Route Name</Link>
</Button>

Conclusion

So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.

Also Read These Solutions

Leave a Comment