<a href="#" className="btn btn-brand me-2">Get Started</a>
I have this button which I want to link to another page
const Signup = () => {.....}
export default Signup;
This is the function builder and export skeletal code for a component which will be the signup/login page for an app. It’s the one I wish to link to via the button above.
function App() {
return (
<div>
<Navbar />
<Hero />
<About />
<Pricing />
<Footer />
</div>
);
}
Here’s my app.js’ function with the different components of my welcome page. Right now, I want the welcome page to act separate, but a couple of buttons on the welcome page should lead to the signup page.
Thanks!
2
Answers
Install react-router-dom if not installed then go through the below code.
react it self is not reliable when it comes to routing
you need to install react-router-dom the same way you installed react via (npm ,yarn,etc..)
once you get it installed you need to wrap your App component like this in the index file
now at you App component you need to define something look like this under you return statement
Routes is the wrapper for all the Route you might have
path is the path after the url,
element is pointing to the component you want to render at this path
lets assume you have button lead to /any-path
you would import Link Component from react-router-dom
then use it like this
Link is woking as
<a href=""></a>
Right now you should try to localhost:port/sign-up, Signup Component should be displayed if it has jsx returned like any regular component
i would recommend React-router-dom Article it would help after then