{"id":89823,"date":"2025-10-15T10:41:40","date_gmt":"2025-10-15T05:11:40","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=89823"},"modified":"2025-11-23T18:10:53","modified_gmt":"2025-11-23T12:40:53","slug":"routing-in-reactjs","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/routing-in-reactjs\/","title":{"rendered":"Routing in ReactJS Simplified: Essential Beginner-Friendly Examples!"},"content":{"rendered":"\n<p>Since the inception of <strong>websites<\/strong> and <strong>software applications<\/strong>, navigation has been one of the most fundamental aspects of <strong>user experience (UX<\/strong>). Imagine a platform where users spend most of their time figuring out how to use its features or where to navigate\u2014awful, isn\u2019t it? That\u2019s why routing is vital in modern React applications.<\/p>\n\n\n\n<p>Routing in ReactJS is managed through <strong>React Router<\/strong>, a<strong> JavaScript library<\/strong> that enables <strong>single-page applications (SPAs) <\/strong>to navigate between components without full page reloads.<\/p>\n\n\n\n<p>Before<strong> React Router<\/strong>, developers manually managed URLs, leading to <strong>messy code, unnecessary reloads, <\/strong>and <strong>poor UX<\/strong>. With React Router, React apps became modular, seamless, and performance-optimized.In this blog, we will explore routing in <strong>ReactJS<\/strong>, covering its essential topics and providing the most effective code examples. So, let&#8217;s begin our discussion.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>React Router &amp; Routing in React: What It Is and Why It Matters<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/React-Router-Routing-in-React_-What-It-Is-and-Why-It-Matters-1200x630.png\" alt=\"\" class=\"wp-image-94060\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/React-Router-Routing-in-React_-What-It-Is-and-Why-It-Matters-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/React-Router-Routing-in-React_-What-It-Is-and-Why-It-Matters-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/React-Router-Routing-in-React_-What-It-Is-and-Why-It-Matters-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/React-Router-Routing-in-React_-What-It-Is-and-Why-It-Matters-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/React-Router-Routing-in-React_-What-It-Is-and-Why-It-Matters-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/React-Router-Routing-in-React_-What-It-Is-and-Why-It-Matters-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p><strong>Routing <\/strong>in <a href=\"https:\/\/www.guvi.in\/blog\/what-is-reactjs\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>ReactJS<\/strong><\/a><strong> <\/strong>is the process of mapping the URLs <strong>(URL mapping)<\/strong> to the respective <a href=\"https:\/\/www.guvi.in\/blog\/introduction-to-react-functional-components\/\" target=\"_blank\" rel=\"noreferrer noopener\">functional components<\/a>. In other words, determining which component should be displayed to the end users based on the URL they visit or navigate. It is an essential part for controlling the entire navigational flow of a React application.&nbsp;<\/p>\n\n\n\n<p>To enable or establish a full-fledged routing system, <strong>React Router<\/strong> (a standard JS library) is integrated into the development process. It provides a <strong>declarative API for defining route paths, mapping URLs to multiple components, handling dynamic parameters,<\/strong> and <strong>managing nested views of components.<\/strong> <strong><em>For better comprehension:<\/em><\/strong> Routing in ReactJS is a navigation concept, while React Router is the software tool through which this concept gets implemented.&nbsp;<\/p>\n\n\n\n<p>If we discuss React Router&#8217;s significance from a core development perspective, it becomes extremely crucial for developers. It allows them to manage <strong>authentication-specific routes, role-based access control, <\/strong>and<strong> build deeply nested frontend layouts without cluttering the program files.&nbsp;<\/strong><\/p>\n\n\n\n<p>Without routing in ReactJS applications, several challenges would arise, such as sophisticated<strong> <\/strong><a href=\"https:\/\/www.guvi.in\/blog\/what-is-dom-manipulation\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>DOM manipulation<\/strong><\/a>, mishandling of <strong>dynamic URLs<\/strong>, and, more importantly, degradation in <strong>user engagement and interaction<\/strong> with the apps.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Implementing Routing in ReactJS: Setup, Navigation, and Advanced Techniques<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Setting Up React Router (Latest Version) &amp; Understanding BrowserRouter, Routes, and Route (v6+)<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Setting-Up-React-Router-Latest-Version-Understanding-BrowserRouter-Routes-and-Route-v6-1200x630.png\" alt=\"\" class=\"wp-image-94062\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Setting-Up-React-Router-Latest-Version-Understanding-BrowserRouter-Routes-and-Route-v6-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Setting-Up-React-Router-Latest-Version-Understanding-BrowserRouter-Routes-and-Route-v6-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Setting-Up-React-Router-Latest-Version-Understanding-BrowserRouter-Routes-and-Route-v6-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Setting-Up-React-Router-Latest-Version-Understanding-BrowserRouter-Routes-and-Route-v6-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Setting-Up-React-Router-Latest-Version-Understanding-BrowserRouter-Routes-and-Route-v6-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Setting-Up-React-Router-Latest-Version-Understanding-BrowserRouter-Routes-and-Route-v6-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>These are the following steps you need to follow to <a href=\"https:\/\/www.guvi.in\/blog\/how-to-setup-react-router-v6-tutorial\/\" target=\"_blank\" rel=\"noreferrer noopener\">set up the React Router<\/a> before developing the applications:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>a. Installing React Router<\/strong><\/h4>\n\n\n\n<p>To implement routing in ReactJS, first, you have to install the <strong>React Router <\/strong><a href=\"https:\/\/www.guvi.in\/blog\/guide-for-react-component-libraries\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>library<\/strong><\/a> by writing the following command:<\/p>\n\n\n\n<p><strong><em>(Code)<\/em><\/strong><\/p>\n\n\n\n<p><strong>{<\/strong><\/p>\n\n\n\n<p>npm install react-router-dom<\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>b. Wrapping Your App with BrowserRouter<\/strong><\/h4>\n\n\n\n<p>Here, the <strong>&lt;BrowserRouter&gt;<\/strong> is a component used to enable routing in your application. Here, the entire <strong>&lt;App \/&gt; <\/strong>component is wrapped inside the &lt;BrowserRouter&gt;, which observes URL changes and renders only the components that users visit. Usually, it wraps your entire application in <strong>index.js <\/strong>or <strong>App.js<\/strong>:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p><strong><em>(Code)<\/em><\/strong><\/p>\n\n\n\n<p><strong>{<\/strong><\/p>\n\n\n\n<p><strong>File: index.js<\/strong><\/p>\n\n\n\n<p>import React from &#8216;react&#8217;;<\/p>\n\n\n\n<p>import ReactDOM from &#8216;react-dom\/client&#8217;;<\/p>\n\n\n\n<p>import { BrowserRouter } from &#8216;react-router-dom&#8217;;<\/p>\n\n\n\n<p>import App from &#8216;.\/App&#8217;;<\/p>\n\n\n\n<p>const root = ReactDOM.createRoot(document.getElementById(&#8216;root&#8217;));<\/p>\n\n\n\n<p>root.render(<\/p>\n\n\n\n<p>&nbsp;&nbsp;&lt;BrowserRouter&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;App \/&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&lt;\/BrowserRouter&gt;<\/p>\n\n\n\n<p>);<\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<ul>\n<li>In this code example, <strong>ReactDOM<\/strong> is the library imported to establish a connection between<strong> React functional components<\/strong> and the actual browser <strong>DOM (Document Object Model)<\/strong>.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/li>\n<\/ul>\n\n\n\n<ul>\n<li>App is the main parent component. The root is the container box where the entire <strong>React<\/strong> app gets rendered. And this root source is created by using:<strong> ReactDOM.createRoot( )<\/strong>.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>document.getElementById(&#8216;root&#8217;) <\/strong>is the method we use to manipulate the <strong>DOM tree<\/strong> by selecting the <a href=\"https:\/\/www.guvi.in\/blog\/html-tutorial-guide-for-web-development\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>HTML<\/strong><\/a> element with the id &#8220;root&#8221; (from the <strong>index.htm<\/strong>l file), where the entire React code is injected.&nbsp;&nbsp;&nbsp;&nbsp;<\/li>\n<\/ul>\n\n\n\n<ul>\n<li>The <strong>render( )<\/strong> method is responsible for instructing the React app what to display inside the root container. In this case, the <strong>&lt;App \/&gt;<\/strong> component will get rendered, which is wrapped inside the <strong>&lt;BrowserRouter&gt;<\/strong> component.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>c. Defining Routes<\/strong><\/h4>\n\n\n\n<p>In React, <strong>Routes <\/strong>are defined using the <strong>&lt;Routes&gt;<\/strong> component, which can hold one or more <strong>&lt;Route&gt;<\/strong> elements. Here, each<strong> &lt;Route&gt;<\/strong> element specifies a navigation path and the components that need to be rendered when any user visits that specific URL.&nbsp;<\/p>\n\n\n\n<p>In simple terms, <strong>Route <\/strong>basically conducts a mapping process by linking the <strong>URL paths<\/strong> with the respective component (element).&nbsp;<\/p>\n\n\n\n<p><strong>Note:<\/strong> In <strong>React Router v6+<\/strong>, component is replaced by element, and you pass it as a <strong>JSX element (&lt;Component \/&gt;)<\/strong>. In this latest version, there is no <strong>&lt;Switch&gt;<\/strong> component; <strong>&lt;Routes&gt; <\/strong>replaces<strong> &lt;Switch&gt;<\/strong> and automatically behaves like it.<\/p>\n\n\n\n<p><strong><em>(Code)<\/em><\/strong><\/p>\n\n\n\n<p><strong>{<\/strong><\/p>\n\n\n\n<p><strong>File: App.js<\/strong><\/p>\n\n\n\n<p>import { Routes, Route } from &#8216;react-router-dom&#8217;;<\/p>\n\n\n\n<p>import Home from &#8216;.\/pages\/Home&#8217;;<\/p>\n\n\n\n<p>import About from &#8216;.\/pages\/About&#8217;;<\/p>\n\n\n\n<p>import Contact from &#8216;.\/pages\/Contact&#8217;;<\/p>\n\n\n\n<p>function App() {<\/p>\n\n\n\n<p>&nbsp;&nbsp;return (<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Routes&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Route path=&#8221;\/&#8221; element={&lt;Home \/&gt;} \/&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Route path=&#8221;\/about&#8221; element={&lt;About \/&gt;} \/&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Route path=&#8221;\/contact&#8221; element={&lt;Contact \/&gt;} \/&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/Routes&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;);<\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<p>export default App;<\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<p>_________________________________________________________________________<\/p>\n\n\n\n<p><strong><em>(Code)<\/em><\/strong><\/p>\n\n\n\n<p><strong>{<\/strong><\/p>\n\n\n\n<p><strong>File: pages\/Home.js<\/strong><\/p>\n\n\n\n<p>import React from &#8216;react&#8217;;<\/p>\n\n\n\n<p>function Home() {<\/p>\n\n\n\n<p>&nbsp;&nbsp;return (<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;div style={{ textAlign: &#8216;center&#8217;, marginTop: &#8217;50px&#8217; }}&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Welcome to the Home Page \ud83c\udfe0&lt;\/h1&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;This is the main page of our website where you can explore everything!&lt;\/p&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;);<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>export default Home;<\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<p><strong>_________________________________________________________________________<\/strong><\/p>\n\n\n\n<p><strong>{<\/strong><\/p>\n\n\n\n<p><strong>File: pages\/About.js<\/strong><\/p>\n\n\n\n<p>import React from &#8216;react&#8217;;<\/p>\n\n\n\n<p>function About() {<\/p>\n\n\n\n<p>&nbsp;&nbsp;return (<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;div style={{ textAlign: &#8216;center&#8217;, marginTop: &#8217;50px&#8217; }}&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;About Us \ud83d\udca1&lt;\/h1&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;We\u2019re a passionate team building amazing React apps with modern tools and clean code.&lt;\/p&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;);<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>export default About;<\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<p><strong>_________________________________________________________________________<\/strong><\/p>\n\n\n\n<p><strong>{<\/strong><\/p>\n\n\n\n<p><strong>File: pages\/Contact.js<\/strong><\/p>\n\n\n\n<p>import React from &#8216;react&#8217;;<\/p>\n\n\n\n<p>function Contact() {<\/p>\n\n\n\n<p>&nbsp;&nbsp;return (<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;div style={{ textAlign: &#8216;center&#8217;, marginTop: &#8217;50px&#8217; }}&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Contact Us &lt;\/h1&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;Have any questions? Reach out to us anytime at contact@example.com.&lt;\/p&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;);<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>export default Contact;<\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<p><strong>Let&#8217;s briefly understand how routing works with the help of the above examples:<\/strong><\/p>\n\n\n\n<ul>\n<li>When any end user navigates to<strong> \u201c\/\u201d<\/strong>, React Router renders the <strong>&lt;Home \/&gt; <\/strong>component. In this example, the frontend will display &#8220;Welcome to the Home Page \u201d.<\/li>\n<\/ul>\n\n\n\n<ul>\n<li>When the user navigates to <strong>\u201c\/about\u201d<\/strong>, React Router renders the <strong>&lt;About \/&gt; <\/strong>component. In this example, the frontend will display \u201cAbout Us \u201d.<\/li>\n<\/ul>\n\n\n\n<ul>\n<li>Similarly, when the user navigates to<strong> \u201c\/contact\u201d<\/strong>, React Router renders the<strong> &lt;Contact \/&gt;<\/strong> component. In this example, the frontend will display \u201cContact Us \u201d.<\/li>\n<\/ul>\n\n\n\n<p><strong><em>For better comprehension:<\/em><\/strong> The routing in ReactJS is dynamic in nature, not static, and is entirely based on<strong> client-side rendering (CSR)<\/strong> instead of <strong>server-side rendering (SSR)<\/strong>, due to which each <strong>React page<\/strong> loads faster, as there is no involvement of fetching details from the server.<\/p>\n\n\n\n<p><strong>Note: <\/strong>We can optimize React for <strong>SSR <\/strong>through Code Splitting, Lazy Loading Components, Server-Side Caching functions, Minimizing the Bundle Size, and many more.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. File Structure for React Routing &amp; Optimized Routing Example<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/File-Structure-for-React-Routing-1200x630.png\" alt=\"\" class=\"wp-image-94063\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/File-Structure-for-React-Routing-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/File-Structure-for-React-Routing-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/File-Structure-for-React-Routing-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/File-Structure-for-React-Routing-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/File-Structure-for-React-Routing-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/File-Structure-for-React-Routing-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>React app development is not just limited to writing code; to ensure<strong> code readability<\/strong> and <strong>maintainability, organizing your program files should be your top priority<\/strong>, as it allows you to make the routing system much easier to handle.&nbsp;<\/p>\n\n\n\n<p>A common and clean structure looks like this:<\/p>\n\n\n\n<p><strong>{<\/strong><\/p>\n\n\n\n<p><strong>src\/<\/strong><\/p>\n\n\n\n<p><strong>\u2502<\/strong><\/p>\n\n\n\n<p><strong>\u251c\u2500\u2500 App.js<\/strong><\/p>\n\n\n\n<p><strong>\u251c\u2500\u2500 index.js<\/strong><\/p>\n\n\n\n<p><strong>\u2502<\/strong><\/p>\n\n\n\n<p><strong>\u251c\u2500\u2500 pages\/ # Components for each route<\/strong><\/p>\n\n\n\n<p><strong>\u2502 \u251c\u2500\u2500 Home.js<\/strong><\/p>\n\n\n\n<p><strong>\u2502 \u251c\u2500\u2500 About.js<\/strong><\/p>\n\n\n\n<p><strong>\u2502 \u251c\u2500\u2500 Contact.js<\/strong><\/p>\n\n\n\n<p><strong>\u2502 \u2514\u2500\u2500 NotFound.js<\/strong><\/p>\n\n\n\n<p><strong>\u2502<\/strong><\/p>\n\n\n\n<p><strong>\u251c\u2500\u2500 components\/ # Reusable UI components<\/strong><\/p>\n\n\n\n<p><strong>\u2502 \u251c\u2500\u2500 Header.js<\/strong><\/p>\n\n\n\n<p><strong>\u2502 \u251c\u2500\u2500 Footer.js<\/strong><\/p>\n\n\n\n<p><strong>\u2502 \u2514\u2500\u2500 Navbar.js<\/strong><\/p>\n\n\n\n<p><strong>\u2502<\/strong><\/p>\n\n\n\n<p><strong>\u2514\u2500\u2500 routes\/ # Optional: route-related config or helpers<\/strong><\/p>\n\n\n\n<p><strong>&nbsp;&nbsp;&nbsp;&nbsp;\u2514\u2500\u2500 AppRoutes.js<\/strong><\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<p><strong><em>(Optimized Code Example)<\/em><\/strong><\/p>\n\n\n\n<p><strong>{<\/strong><\/p>\n\n\n\n<p><strong>File: src\/routes\/AppRoutes.js<\/strong><\/p>\n\n\n\n<p>\/\/ src\/routes\/AppRoutes.js<\/p>\n\n\n\n<p>import Home from &#8216;..\/pages\/Home&#8217;;<\/p>\n\n\n\n<p>import About from &#8216;..\/pages\/About&#8217;;<\/p>\n\n\n\n<p>import Contact from &#8216;..\/pages\/Contact&#8217;;<\/p>\n\n\n\n<p>import NotFound from &#8216;..\/pages\/NotFound&#8217;;<\/p>\n\n\n\n<p>export const routes = [<\/p>\n\n\n\n<p>&nbsp;&nbsp;{ path: &#8216;\/&#8217;, element: &lt;Home \/&gt; },<\/p>\n\n\n\n<p>&nbsp;&nbsp;{ path: &#8216;\/about&#8217;, element: &lt;About \/&gt; },<\/p>\n\n\n\n<p>&nbsp;&nbsp;{ path: &#8216;\/contact&#8217;, element: &lt;Contact \/&gt; },<\/p>\n\n\n\n<p>&nbsp;&nbsp;{ path: &#8216;*&#8217;, element: &lt;NotFound \/&gt; },<\/p>\n\n\n\n<p>];<\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<p><strong>_________________________________________________________________________<\/strong><\/p>\n\n\n\n<p><strong>{<\/strong><\/p>\n\n\n\n<p><strong>File: App.js<\/strong><\/p>\n\n\n\n<p>import { Routes, Route } from &#8216;react-router-dom&#8217;;<\/p>\n\n\n\n<p>import { routes } from &#8216;.\/routes\/AppRoutes&#8217;;<\/p>\n\n\n\n<p>function App() {<\/p>\n\n\n\n<p>&nbsp;&nbsp;return (<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Routes&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{routes.map((route, index) =&gt; (<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Route key={index} path={route.path} element={route.element} \/&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;))}<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/Routes&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;);<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<ul>\n<li>In this example, kindly observe how we created a separate file, <strong>AppRoutes.js,<\/strong> for centralizing all the route definitions <strong>(path, associated component)<\/strong>.&nbsp;&nbsp;<\/li>\n<\/ul>\n\n\n\n<ul>\n<li>After that, we imported the routes array into the main<strong> App.js<\/strong> file and implemented the map method. By writing less code, we attached all the essential properties to each Route component, such as a <strong>unique key, path,<\/strong> and<strong> child component<\/strong> to be rendered.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Using Link and NavLink for Navigation<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Using-Link-and-NavLink-for-Navigation-1200x630.png\" alt=\"\" class=\"wp-image-94064\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Using-Link-and-NavLink-for-Navigation-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Using-Link-and-NavLink-for-Navigation-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Using-Link-and-NavLink-for-Navigation-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Using-Link-and-NavLink-for-Navigation-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Using-Link-and-NavLink-for-Navigation-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Using-Link-and-NavLink-for-Navigation-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p><strong>&lt;Link&gt;:<\/strong> This component is used as a replacement for the <strong>&lt;a&gt;<\/strong> tag in React apps; it is essentially a simple way to navigate to a route.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p><strong>&lt;NavLink&gt;:&nbsp; <\/strong>It is equivalent to the <strong>&lt;Link&gt;<\/strong> component but has extra features, adding an <strong>active class<\/strong> and applying custom <a href=\"https:\/\/www.guvi.in\/blog\/essential-css-properties\/\" target=\"_blank\" rel=\"noreferrer noopener\">styling<\/a> on it, to ensure active page links are visually highlighted (as in this case with <strong>bold font weight &amp; blue text color<\/strong>).<\/p>\n\n\n\n<p><strong><em>(Code)<\/em><\/strong><\/p>\n\n\n\n<p><strong>{<\/strong><\/p>\n\n\n\n<p><strong>File: components\/Navbar.js<\/strong><\/p>\n\n\n\n<p>import React from &#8216;react&#8217;;<\/p>\n\n\n\n<p>import { Link, NavLink } from &#8216;react-router-dom&#8217;;<\/p>\n\n\n\n<p>function Navbar() {<\/p>\n\n\n\n<p>&nbsp;&nbsp;const activeStyle = {<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;fontWeight: &#8216;bold&#8217;,<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;color: &#8216;blue&#8217;,<\/p>\n\n\n\n<p>&nbsp;&nbsp;};<\/p>\n\n\n\n<p>&nbsp;&nbsp;return (<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;nav style={{ display: &#8216;flex&#8217;, gap: &#8217;20px&#8217;, padding: &#8217;20px&#8217; }}&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\/* Simple Link *\/}<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Link to=&#8221;\/&#8221;&gt;Home&lt;\/Link&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\/* NavLink with active styling *\/}<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;NavLink to=&#8221;\/about&#8221; style={({ isActive }) =&gt; (isActive ? activeStyle : undefined)}&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;About<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/NavLink&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;NavLink to=&#8221;\/contact&#8221; style={({ isActive }) =&gt; (isActive ? activeStyle : undefined)}&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Contact<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/NavLink&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/nav&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;);<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>export default Navbar;<\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<ul>\n<li>Upon clicking the<strong> &lt;Link&gt;<\/strong> or <strong>&lt;NavLink&gt; <\/strong>component changes the <strong>URL<\/strong> without rendering the whole page.&nbsp;&nbsp;&nbsp;&nbsp;<\/li>\n<\/ul>\n\n\n\n<ul>\n<li>The<strong> &lt;NavLink&gt;<\/strong> component automatically applies the active styles when the route matches the current URL.<\/li>\n<\/ul>\n\n\n\n<ul>\n<li>It becomes easier to add custom style or <strong>className conditional <\/strong><a href=\"https:\/\/www.guvi.in\/blog\/how-to-use-props-in-react\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>props <\/strong><\/a><strong>(properties) <\/strong>with a function that will check the <strong>isActive<\/strong> status of the links.<\/li>\n<\/ul>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Nested Routes Explained<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Nested-Routes-in-ReactJS-1200x630.png\" alt=\"\" class=\"wp-image-94065\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Nested-Routes-in-ReactJS-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Nested-Routes-in-ReactJS-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Nested-Routes-in-ReactJS-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Nested-Routes-in-ReactJS-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Nested-Routes-in-ReactJS-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Nested-Routes-in-ReactJS-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p><strong>Nested Routes<\/strong> is a routing structure in which users can render the navigational routes inside other <strong>parent routes<\/strong>. By doing this, it becomes easier to create page layouts that include shared components like <strong>headers, navbars, sidebars, <\/strong>or <strong>footers.&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/p>\n\n\n\n<p>It is one of the effective methods to eliminate code repetitiveness; you just define a parent route and render all the<strong> child routes <\/strong>inside it.<\/p>\n\n\n\n<p><strong><em>(Code)<\/em><\/strong><\/p>\n\n\n\n<p><strong>{<\/strong><\/p>\n\n\n\n<p><strong>File: App.js<\/strong><\/p>\n\n\n\n<p>import { Routes, Route } from &#8216;react-router-dom&#8217;;<\/p>\n\n\n\n<p>import Layout from &#8216;.\/pages\/Layout&#8217;;<\/p>\n\n\n\n<p>import Home from &#8216;.\/pages\/Home&#8217;;<\/p>\n\n\n\n<p>import About from &#8216;.\/pages\/About&#8217;;<\/p>\n\n\n\n<p>import Contact from &#8216;.\/pages\/Contact&#8217;;<\/p>\n\n\n\n<p>import NotFound from &#8216;.\/pages\/NotFound&#8217;;<\/p>\n\n\n\n<p>function App() {<\/p>\n\n\n\n<p>&nbsp;&nbsp;return (<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Routes&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\/* Parent layout route *\/}<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Route path=&#8221;\/&#8221; element={&lt;Layout \/&gt;}&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\/* Nested routes *\/}<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Route index element={&lt;Home \/&gt;} \/&gt; {\/* Default page *\/}<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Route path=&#8221;about&#8221; element={&lt;About \/&gt;} \/&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Route path=&#8221;contact&#8221; element={&lt;Contact \/&gt;} \/&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Route path=&#8221;*&#8221; element={&lt;NotFound \/&gt;} \/&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/Route&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/Routes&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;);<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>export default App;<\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<p><strong>_________________________________________________________________________<\/strong><\/p>\n\n\n\n<p><strong>{<\/strong><\/p>\n\n\n\n<p><strong>File: pages\/Layout.js<\/strong><\/p>\n\n\n\n<p>import React from &#8216;react&#8217;;<\/p>\n\n\n\n<p>import { Outlet, NavLink } from &#8216;react-router-dom&#8217;;<\/p>\n\n\n\n<p>function Layout() {<\/p>\n\n\n\n<p>&nbsp;&nbsp;const activeStyle = { fontWeight: &#8216;bold&#8217;, color: &#8216;blue&#8217; };<\/p>\n\n\n\n<p>&nbsp;&nbsp;return (<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\/* Navbar *\/}<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;nav style={{ display: &#8216;flex&#8217;, gap: &#8217;20px&#8217;, padding: &#8217;20px&#8217; }}&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;NavLink to=&#8221;\/&#8221; end style={({ isActive }) =&gt; (isActive ? activeStyle : undefined)}&gt;Home&lt;\/NavLink&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;NavLink to=&#8221;about&#8221; style={({ isActive }) =&gt; (isActive ? activeStyle : undefined)}&gt;About&lt;\/NavLink&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;NavLink to=&#8221;contact&#8221; style={({ isActive }) =&gt; (isActive ? activeStyle :&nbsp;<\/p>\n\n\n\n<p>undefined)}&gt;Contact&lt;\/NavLink&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/nav&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\/* Nested route content will render here *\/}<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Outlet \/&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;);<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>export default Layout;<\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<ul>\n<li><strong>Parent Route (Layout): <\/strong>Contains the <strong>shared layout<\/strong>, e.g., Navbar.<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>&lt;Outlet \/&gt;: <\/strong>Placeholder where <strong>nested child routes<\/strong> render.<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>Child Routes (Home, About, Contact): <\/strong>Render inside the <strong>&lt;Layout&gt; <\/strong>automatically.<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>index route: <\/strong>Serves as the <strong>default child page<\/strong> when parent path \/ is visited.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Handling 404 Pages (Not Found Routes)<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Handling-404-Pages-Not-Found-Routes-1200x630.png\" alt=\"\" class=\"wp-image-94066\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Handling-404-Pages-Not-Found-Routes-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Handling-404-Pages-Not-Found-Routes-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Handling-404-Pages-Not-Found-Routes-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Handling-404-Pages-Not-Found-Routes-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Handling-404-Pages-Not-Found-Routes-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Handling-404-Pages-Not-Found-Routes-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>Along with defining all the routes, it is also necessary to include code scripts for<strong> handling 404 Pages<\/strong>. The reason behind this is to maintain the application&#8217;s consistency and workflow, particularly when users visit<strong> URLs<\/strong> that don&#8217;t match any defined routes.&nbsp;<\/p>\n\n\n\n<p>In other words, letting the end users know that the page doesn&#8217;t exist instead of showing a <strong>blank <\/strong><a href=\"https:\/\/www.guvi.in\/blog\/what-is-user-interface\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>interface<\/strong><\/a>.<\/p>\n\n\n\n<p><strong><em>(Code)<\/em><\/strong><\/p>\n\n\n\n<p><strong>{<\/strong><\/p>\n\n\n\n<p><strong>File: App.js<\/strong><\/p>\n\n\n\n<p>import { Routes, Route } from &#8216;react-router-dom&#8217;;<\/p>\n\n\n\n<p>import Home from &#8216;.\/pages\/Home&#8217;;<\/p>\n\n\n\n<p>import About from &#8216;.\/pages\/About&#8217;;<\/p>\n\n\n\n<p>import Contact from &#8216;.\/pages\/Contact&#8217;;<\/p>\n\n\n\n<p>import NotFound from &#8216;.\/pages\/NotFound&#8217;;<\/p>\n\n\n\n<p>function App() {<\/p>\n\n\n\n<p>&nbsp;&nbsp;return (<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Routes&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Route path=&#8221;\/&#8221; element={&lt;Home \/&gt;} \/&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Route path=&#8221;\/about&#8221; element={&lt;About \/&gt;} \/&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Route path=&#8221;\/contact&#8221; element={&lt;Contact \/&gt;} \/&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\/* Catch-all route for 404 *\/}<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Route path=&#8221;*&#8221; element={&lt;NotFound \/&gt;} \/&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/Routes&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;);<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>export default App;<\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<p><strong>_________________________________________________________________________<\/strong><\/p>\n\n\n\n<p><strong>{<\/strong><\/p>\n\n\n\n<p><strong>File: pages\/NotFound.js<\/strong><\/p>\n\n\n\n<p>import React from &#8216;react&#8217;;<\/p>\n\n\n\n<p>import { Link } from &#8216;react-router-dom&#8217;;<\/p>\n\n\n\n<p>function NotFound() {<\/p>\n\n\n\n<p>&nbsp;&nbsp;return (<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;div style={{ textAlign: &#8216;center&#8217;, marginTop: &#8217;50px&#8217; }}&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;404 &#8211; Page Not Found &lt;\/h1&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;The page you are looking for does not exist.&lt;\/p&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Link to=&#8221;\/&#8221;&gt;Go back Home&lt;\/Link&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;);<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>export default NotFound;<\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<ol>\n<li><strong>path=&#8221;*&#8221;<\/strong><\/li>\n<\/ol>\n\n\n\n<ul>\n<li>Matches <strong>any URL<\/strong> that doesn\u2019t match the defined routes.<\/li>\n\n\n\n<li>This ensures the 404 page is shown for invalid URLs.<\/li>\n<\/ul>\n\n\n\n<ol start=\"2\">\n<li><strong>User-friendly message<\/strong><\/li>\n<\/ol>\n\n\n\n<ul>\n<li>Let users know the page isn\u2019t found.<\/li>\n\n\n\n<li>Provide a <strong>link to go back home<\/strong> or to other important pages.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Best Practices for React Routing (2025)<\/strong><\/h2>\n\n\n\n<p>The following are the best practices while performing routing in React applications:<\/p>\n\n\n\n<ul>\n<li><strong>Organize Routes<\/strong> \u2013 Keep routes in a central file.<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>Use Nested Routes<\/strong> \u2013 Share layouts like Navbar\/Footer.<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>Highlight Active Links<\/strong> \u2013 Use NavLink for the current page.<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>Handle 404 Pages<\/strong> \u2013 Include a catch-all route.<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>Keep Routes Simple<\/strong> \u2013 Avoid overly complex nesting.<\/li>\n<\/ul>\n\n\n\n<p>In today&#8217;s time, cracking a top product-based company requires a solid foundation in programming and hands-on experience in developing real-world projects. But to acquire proficiency in these fields is not an easy task; for that, you need a tech mentor who can guide you through all the intricacies involved in software development processes. If you constantly aspire to become a software developer but don&#8217;t know how to start, enroll in <strong>HCL GUVI&#8217;s IITM Pravartak Certified<\/strong><a href=\"https:\/\/www.guvi.in\/zen-class\/full-stack-development-course\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=Routing+in+ReactJS+Simplified%3A+Essential+Beginner-Friendly+Examples%21\" target=\"_blank\" rel=\"noreferrer noopener\"> <strong>MERN Full Stack Development Course<\/strong><\/a> <strong>with AI Integration<\/strong>. Equip yourself with the in-demand tools and unlock a high-paying tech career.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p><strong>React Router<\/strong> makes it easy to create <strong>single-page applications<\/strong> with multiple pages and smooth navigation. By using <strong>BrowserRouter, Routes, <\/strong>and<strong> Route<\/strong>, you can define both static and dynamic routes. Components like <strong>Link <\/strong>and<strong> NavLink <\/strong>allow users to navigate seamlessly, while nested routes help organize layouts with shared components. Including a <strong>404 page <\/strong>ensures a professional and user-friendly experience.<\/p>\n\n\n\n<p>For beginners, focusing on these essentials provides a solid foundation for building React apps with clean and maintainable routing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>FAQs<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1760466672984\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>What is React Router, and why do we need it?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>React Router lets React apps have <strong>multiple pages<\/strong> without reloading the browser, enabling smooth navigation.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1760466680522\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>What\u2019s the difference between Link and NavLink?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The <strong>Link<\/strong> component is for basic navigation, while NavLink can highlight the active page automatically.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1760466692908\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>How do I handle pages that don\u2019t exist (404)?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Use a <strong>catch-all route<\/strong> (path=&#8221;*&#8221;) to render a <strong>NotFound component<\/strong> for unmatched URLs.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Since the inception of websites and software applications, navigation has been one of the most fundamental aspects of user experience (UX). Imagine a platform where users spend most of their time figuring out how to use its features or where to navigate\u2014awful, isn\u2019t it? That\u2019s why routing is vital in modern React applications. Routing in [&hellip;]<\/p>\n","protected":false},"author":64,"featured_media":94059,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[907,294,429],"tags":[],"views":"1765","authorinfo":{"name":"Abhishek Pati","url":"https:\/\/www.guvi.in\/blog\/author\/abhishek-pati\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/10\/Routing-in-ReactJS-Simplified-Essential-Beginner-Friendly-Examples-300x116.png","jetpack_featured_media_url":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/10\/Routing-in-ReactJS-Simplified-Essential-Beginner-Friendly-Examples.png","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/89823"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/64"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=89823"}],"version-history":[{"count":6,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/89823\/revisions"}],"predecessor-version":[{"id":94068,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/89823\/revisions\/94068"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/94059"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=89823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=89823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=89823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}