javascript
Navigate or link to another page React
//INSTALLATTION - npm install react-router-dom
import React from "react";
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
export default function App() {
return (
<div>
<ul>
<li><Link to="/">Home</Link></li>
<li><Link to="/about">About</Link></li>
<li><Link to="/contact">Contact</Link></li>
</ul>
<Router>
<Route exact path="/" component={Home} />
<Route exact path="/about" component={About} />
<Route exact path="/contact" component={Contact} />
</Router>
</div>
);
}
Package Installation
npm install react-router-dom
You can use the react-router-dom npm package to navigate to other pages or components in React.
Was this helpful?
Similar Posts
- Navigate to Page with parameters
- open link in new tab using javascript
- Replace array values with another value Lodash
- Pass a function as parameter of another function in Javascript
- allows keeping the URL while rendering a different page
- jQuery code to run a function after page load
- Web Page with 3 cards Displaying images