Link Component in React Router
Last Updated :
24 Apr, 2025
React Router is a powerful library in ReactJS that is used to create SPA (single-page applications) seamlessly. One of the components of the React Router is Link.
In this article, we will be seeing the working of the Link component, various props, and usage of the Link component within React Router in developing Single Page Applications.
Prerequisites:
Working of Link Component:
The link component is used for Routing from one page to another page without loading the page itself. This happens with the help of the react-router-dom module which contains (Browser Router, Routes, and Route) along with the Link component. So, when a user clicks on a link to navigate to another page, then that path is captured by the link component and compared with the path of the components wrapped inside the router. If it matches, then that page is rendered without any reload.
What are Props ?
In react, the components have some properties which are known as props to customize their behavior. The Link components have several props that help to control their behavior during navigation. let us see the different types of props and their examples.
What is 'to' prop ?
This is the most used props for routing. It helps in specifying the target location to which the link should navigate. It can be a string representing the path name or an object with path name. When you click on Dashboard you will be redirected to that component.
Syntax of 'to' prop:
Dashboard
What is 'reloadDocument' prop ?
This prop controls whether a full page reload should occur when the link is clicked. setting it true will reload the page which can be useful in certain cases.
Syntax of 'reloadDocument' prop:
Contact
What is 'replace' prop ?
When you use this prop with the link component, it means that when the user clicks on the link, the current page history in the browser will be replaced by the new one. means that the current page won't be remembered in the history, assuming as if the user never visited that page ever.
Syntax of 'replace' prop:
About
This prop is used to overcome the default behavior of scrolling to the top position if navigated to another component. If suppose the user is reading a blog and he clicks on comment section with 'preventScrollReset = {true}' then the page will navigate to the comment section without resetting the scroll position. without 'preventScrollReset' the default behavior will scroll the user back to the top page when they navigate to a new location.
Syntax of 'preventScrollReset':
Go to Blog
Parsing Attributes
Sometimes it is important to pass additional attributes to the Link component. We can achieve this by passing the props directly to the Link Component. Here in the below example, I have added two additional props such as className for styling the link and target attribute to navigate to the location in new tab.
Syntax to pass attributes:
Home
Use of Link Component:
- First create the components that you want to navigate to. for example, Home.jsx
- In your App.jsx, wrap the components inside a Router and define the routes using the Route component. Mention the path and element name inside the route for that respective component.
- Create one more component (for example: Navbar.jsx) and render it inside Home.jsx, About.jsx and Contact.jsx this component contains the Link tag which has the exact same path (declared in variable "to") as the route has in it.
Example: Below is an example of link component in React Router.
JavaScript
// App.jsx
import {
BrowserRouter as Router,
Routes,
Route
} from "react-router-dom";
import Home from "./Home";
import About from "./About";
import Contact from "./Contact";
function App() {
return (
<>
<Router>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
<Route path="/contact" element={<Contact />} />
</Routes>
</Router>
</>
);
}
export default App;
JavaScript
// Navbar.jsx
import React from "react";
import { Link } from "react-router-dom";
const Navbar = () => {
return (
<>
<div
className="nav"
style={{
display: "flex",
justifyContent: "space-evenly",
marginTop: "1rem",
color: "green",
fontWeight: "bolder",
fontSize: "1rem",
}}
>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
<Link to="/contact">Contact Us</Link>
</div>
</>
);
};
export default Navbar;
JavaScript
// Home.jsx
import React from "react";
import Navbar from "./Navbar";
const Home = () => {
return (
<>
<Navbar /> <br />
<div style={{
display: "flex",
justifyContent: "center"
}}>
This is
<span style={{ color: "green" }}>
GeeksForGeeks
</span>
Home
Page
</div>
</>
);
};
export default Home;
JavaScript
// About.jsx
import React from "react";
import Navbar from "./Navbar";
const About = () => {
return (
<>
<Navbar /> <br />
<div style={{
display: "flex",
justifyContent: "center"
}}>
This is
<span style={{ color: "green" }}>
GeeksForGeeks
</span>
About Page
</div>
</>
);
};
export default About;
JavaScript
// Contact.jsx
import React from "react";
import Navbar from "./Navbar";
const Contact = () => {
return (
<>
<Navbar /> <br />
<div style={{
display: "flex",
justifyContent: "center"
}}>
This is <span style={{ color: "green" }}>
GeeksForGeeks
</span>
Contact Page
</div>
</>
);
};
export default Contact;
Output:

Similar Reads
Navigate Component in React Router
The navigate component is among the built-in components shipped in with React router version 6. It is a component similar to the useNavigate hook. Internally it uses useNavigate to redirect the location. The props passed to Navigate are the same as the arguments passed to the function returned by us
4 min read
Route Component in React Router
React Router is a popular library used for managing routing in React applications. At its core lies the Route component, which plays a pivotal role in defining the relationship between URLs and corresponding components. In this article, we'll delve into the intricacies of the Route component, explor
5 min read
Await Component in React Router
The <Await> component in React Router v6 is designed to handle the rendering of deferred values with automatic error handling. It is especially useful when dealing with asynchronous data fetching in components rendered by React Router routes. The <Await> component ensures that the render
5 min read
React Rebass Link Component
React Rebass is a front-end framework that was designed keeping react in mind. In this article, we will know how to use Link Component in React Rebass. The Link is an important component that is required in each development. So to create a Link component we can import the Rebass Link component. The
2 min read
How to use Link Component in React JS?
Material-UI provides a set of components that can be seamlessly integrated with React to create visually appealing and functional navigation elements. The Link component allows you to easily customize anchor elements with our own theme colors and typography styles. Material UI for React has this com
2 min read
Routes Component in React Router
Routes are an integral part of React Router, facilitating the navigation and rendering of components based on URL patterns. In this article, we'll delve into the concept of routes, understanding their role in React Router, and how to define and manage routes effectively. Table of Content What are Ro
4 min read
Link and NavLink components in React-Router-Dom
When creating a React app, handling navigation properly is important. React Router provides two key components, Link and NavLink, to make moving between pages easy. These components work like regular <a> tags but prevent full-page reloads, making the app faster and smoother for users. What is
5 min read
React Suite Pagination Component
React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. Pagination component allows the user to select a specific page from a range of pages. We can use the following approach in ReactJS to use the React Suite Paginat
3 min read
React Suite Nav Component
React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. Nav component allows the user to provide a list of various forms of navigation menus. We can use the following approach in ReactJS to use the React Suite Nav Com
3 min read
React Suite Portal Component
React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. Portal component renders its children into a new subtree outside the current DOM hierarchy. We can use the following approach in ReactJS to use the React Suite P
2 min read