{"id":6403,"date":"2021-06-19T08:19:00","date_gmt":"2021-06-19T08:19:00","guid":{"rendered":"https:\/\/programmingfields.com\/?p=6403"},"modified":"2026-05-02T06:29:33","modified_gmt":"2026-05-02T06:29:33","slug":"create-react-routing-in-react-js-using-react-router-dom","status":"publish","type":"post","link":"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/","title":{"rendered":"Brief Overview of React Routing Using React Router DOM"},"content":{"rendered":"\n<p>Do you want to handle and render multiple components in React? If yes then this post is only for you. Yeah, I am talking about navigating from component to component. While navigating to components the page doesn&#8217;t refresh in React. Also, it needs to change the route dynamically. If you render the child components in a parent then it will be rendered one after one by default. So, what if you don&#8217;t want to render all components at the same time? Here, we will use <strong>React router <\/strong>to handle the components navigation and routing. Every time when you will navigate to another component, you can set the route for it. For managing routing, React uses the <strong>React Router DOM<\/strong>.<\/p>\n\n\n\n<p>Also, on the basis of the route, you can set the component that you want to load. Even you can manage the redirection through the browser URL. In this React post, I will be giving you a brief overview of <strong>React Router DOM<\/strong>. To manage the react routes, we will use the React Router DOM.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#React_Router\" >React Router<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Why_React_Router\" >Why React Router<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Prerequisites\" >Prerequisites<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Create_React_App_For_Implementing_React_Router\" >Create React App For Implementing React Router<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Install_Bootstrap_in_React_js\" >Install Bootstrap in React js<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Import_Bootstrap_in_React\" >Import Bootstrap in React<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Create_Components_in_React_JS\" >Create Components in React JS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Create_a_Navigation_Bar_in_React_JS\" >Create a Navigation Bar in React JS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Create_Home_About_and_Contact_Component\" >Create Home, About, and Contact Component<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Render_Components_in_React_JS\" >Render Components in React JS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Install_React_Router_DOM_in_React_JS\" >Install React Router DOM in React JS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Use_of_React_Route\" >Use of React Route<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Get_Result_of_Using_React_Route\" >Get Result of Using React Route<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Use_of_Link_Component_in_React_JS\" >Use of Link Component in React JS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Use_NavLink_Component_in_React_For_Active_Link\" >Use NavLink Component in React For Active Link<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Conflict_of_Having_Multiple_Same_Routes\" >Conflict of Having Multiple Same Routes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Use_of_Switch_Component_in_React_JS\" >Use of Switch Component in React JS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/programmingfields.com\/create-react-routing-in-react-js-using-react-router-dom\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"React_Router\"><\/span><strong>React Router<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>React Router is a collection of&nbsp;<strong>navigational components<\/strong>&nbsp;that compose declaratively with your application. It allows changing the <strong>browser URL<\/strong> and keeps the components linked with the URL. Even it uses dynamic routing. React Router provides two different routing systems.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Web<\/strong> &#8211; It is used in React JS web applications.<\/li>\n\n\n\n<li><strong>Mobile<\/strong> &#8211; It is for a mobile application that is used by React Native.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_React_Router\"><\/span><strong>Why React Router<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We use React JS for the single-page application. React Router, allows us to build a single-page web application with navigation. It loads components without the page refreshing as the user navigates. React Router uses component structure to call components.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Prerequisites\"><\/span><strong>Prerequisites<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>I am sure your system is ready to create a React app. If not then you have to install the&nbsp;<strong>Node.js<\/strong>&nbsp;<strong>&gt;= 10<\/strong>. <\/p>\n\n\n\n<p>If you are an absolute beginner in React. And you have no idea about the installation then follow up on my previous post. I have already shared a post on <a href=\"https:\/\/programmingfields.com\/how-to-install-react-in-windows-and-linux-step-by-step\/\" target=\"_blank\" rel=\"noreferrer noopener\">how to start with a React app<\/a>.<\/p>\n\n\n\n<p>Now, let&#8217;s create a new app in React js.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_React_App_For_Implementing_React_Router\"><\/span><strong>Create React App For Implementing React Router<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To create a new app in React, just open the terminal or command prompt and hit the below command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">npx create-react-app blog<\/code><\/pre>\n\n\n\n<p>The above command will start the installation of React js in the specified folder.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"803\" height=\"606\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-17-08-41-27.png?resize=803%2C606&#038;ssl=1\" alt=\"Create React App \" class=\"wp-image-6415\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-17-08-41-27.png?w=803&amp;ssl=1 803w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-17-08-41-27.png?resize=300%2C226&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-17-08-41-27.png?resize=768%2C580&amp;ssl=1 768w\" sizes=\"auto, (max-width: 803px) 100vw, 803px\" \/><figcaption class=\"wp-element-caption\"><strong>Create React App For React Router Implementation <\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<p>After creating the React app, you need to navigate to the folder and run it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">npm start<\/code><\/pre>\n\n\n\n<p>It will start<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"703\" height=\"413\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-18-20-31-57.png?resize=703%2C413&#038;ssl=1\" alt=\"React Homepage\" class=\"wp-image-6420\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-18-20-31-57.png?w=703&amp;ssl=1 703w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-18-20-31-57.png?resize=300%2C176&amp;ssl=1 300w\" sizes=\"auto, (max-width: 703px) 100vw, 703px\" \/><figcaption class=\"wp-element-caption\"><strong>React Homepage<\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<p>Before moving to the React routes implementation, I would like to install Bootstrap.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/programmingfields.com\/create-a-todo-app-in-react-using-laravel-8-restful-apis\/\" target=\"_blank\" rel=\"noreferrer noopener\">Create a Todo App in React Using Laravel 8 RESTful APIs<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Install_Bootstrap_in_React_js\"><\/span><strong>Install Bootstrap in React js<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you have no idea about the third party packages in React then go to the official website of <a rel=\"noreferrer noopener\" href=\"https:\/\/www.npmjs.com\/\" target=\"_blank\">npm js<\/a>. You can install the third party available packages from here. So, I will search for the Bootstrap.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"380\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-12-08.png?resize=1024%2C380&#038;ssl=1\" alt=\"Search Bootstrap Package in npmjs\" class=\"wp-image-6424\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-12-08.png?resize=1024%2C380&amp;ssl=1 1024w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-12-08.png?resize=300%2C111&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-12-08.png?resize=768%2C285&amp;ssl=1 768w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-12-08.png?resize=270%2C100&amp;ssl=1 270w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-12-08.png?w=1201&amp;ssl=1 1201w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption class=\"wp-element-caption\"><strong>Search Bootstrap Package in npmjs<\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<p>You can check the command for the installation. Now, you have to come back to your terminal and hit the below command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">npm i bootstrap<\/code><\/pre>\n\n\n\n<p>Here, I want to have the latest version of Bootstrap. Hence, I haven&#8217;t specified the version. If you want any specific version then you can put it up here.<\/p>\n\n\n\n<p>It will take a couple of seconds to install the package inside your project.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"805\" height=\"293\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-25-17.png?resize=805%2C293&#038;ssl=1\" alt=\"Install Bootstrap in React js\" class=\"wp-image-6426\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-25-17.png?w=805&amp;ssl=1 805w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-25-17.png?resize=300%2C109&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-25-17.png?resize=768%2C280&amp;ssl=1 768w\" sizes=\"auto, (max-width: 805px) 100vw, 805px\" \/><figcaption class=\"wp-element-caption\"><strong>Install Bootstrap in React js<\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<p>You can check the installed package inside the project. You need to got to the<strong> package.json<\/strong> file.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"706\" height=\"383\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-29-06.png?resize=706%2C383&#038;ssl=1\" alt=\"package.json\" class=\"wp-image-6427\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-29-06.png?w=706&amp;ssl=1 706w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-29-06.png?resize=300%2C163&amp;ssl=1 300w\" sizes=\"auto, (max-width: 706px) 100vw, 706px\" \/><figcaption class=\"wp-element-caption\"><strong>React package.json<\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/programmingfields.com\/react-login-and-registration-app-using-laravel-7-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">React Login and Registration App Using Laravel 7 API<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Import_Bootstrap_in_React\"><\/span><strong>Import Bootstrap in React<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Before using the Bootstrap classes in<strong> React JSX <\/strong>you need to import the CSS and JS. So, according to the React js file structure, we have the <strong>index.js<\/strong> file. Hence,  you need to import it inside the <strong>index.js <\/strong>file. This will be the global, so we can use it in every component.<\/p>\n\n\n\n<pre title=\"index.js\" class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import React from 'react';\nimport ReactDOM from 'react-dom';\nimport App from '.\/App';\n\n\/\/ import bootstrap\nimport '..\/node_modules\/bootstrap\/dist\/css\/bootstrap.min.css';\nimport '..\/node_modules\/bootstrap\/dist\/js\/bootstrap.min.js'\n\nReactDOM.render(\n  &lt;React.StrictMode&gt;\n    &lt;App \/&gt;\n  &lt;\/React.StrictMode&gt;,\n  document.getElementById('root')\n);<\/code><\/pre>\n\n\n\n<p>In this post, I will be creating navigation bar using the Boostrap 5. So, that you can have the better understanding of the React Routers and React Router Link. Because, through the navigation bar, we will have the multiple links and we can checkout everything here. <\/p>\n\n\n\n<p>Hence, let&#8217;s create some components here.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/programmingfields.com\/crud-app-in-react-js-using-laravel-7-restful-api\/\">Create a CRUD App in React.js Using Laravel 7 RESTful API<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_Components_in_React_JS\"><\/span><strong>Create Components in React JS<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For creating the navigation and the <strong>React Router<\/strong>, create the following components one by one. But, before that, create a folder with the name <strong>components<\/strong> inside the <strong>src<\/strong> folder.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Header.js<\/strong><\/li>\n\n\n\n<li><strong>Home.js<\/strong><\/li>\n\n\n\n<li><strong>About.js<\/strong><\/li>\n\n\n\n<li><strong>Contact.js<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">src\n |___ components\n        |__ Header.js\n        |__ Home.js\n        |__ About.js\n        |__ Contact.js                  <\/code><\/pre>\n\n\n\n<p>After creating the above components, firstly, create a navigation bar using Bootstrap 5. Hence, we will use the <strong>Header<\/strong> component for the navigation bar. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_a_Navigation_Bar_in_React_JS\"><\/span><strong>Create a Navigation Bar in React JS<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Navigate to the Header component and let&#8217;s add the below snippet there. Here, I have created the class component.<\/p>\n\n\n\n<pre title=\"Header.js\" class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import React from 'react';\n\nexport default class Header extends React.Component {\n    render() {\n        return (\n            &lt;nav className=\"navbar navbar-expand-lg navbar-dark bg-dark sticky-top\"&gt;\n                &lt;div className=\"container\"&gt;\n                    &lt;a href=\"#\" className=\"navbar-brand\"&gt;Programming Fields&lt;\/a&gt;\n                    &lt;button className=\"navbar-toggler\" type=\"button\" data-bs-toggle=\"collapse\" data-bs-target=\"#navbarNavAltMarkup\" aria-controls=\"navbarNavAltMarkup\" aria-expanded=\"false\" aria-label=\"Toggle navigation\"&gt;\n                        &lt;span className=\"navbar-toggler-icon\"&gt;&lt;\/span&gt;\n                    &lt;\/button&gt;\n                    &lt;div className=\"collapse navbar-collapse\" id=\"navbarNavAltMarkup\"&gt;\n                        &lt;ul className=\"navbar-nav ms-auto\"&gt;\n                            &lt;li className=\"navbar-item\"&gt;\n                               &lt;a href=\"#\" className=\"nav-link\" aria-current=\"page\"&gt;Home&lt;\/a&gt;\n                            &lt;\/li&gt;\n                            &lt;li className=\"navbar-item\"&gt;\n                               &lt;a href=\"#\" className=\"nav-link\"&gt;About Us&lt;\/a&gt;\n                            &lt;\/li&gt;\n                            &lt;li className=\"navbar-item\"&gt;\n                               &lt;a href=\"#\" className=\"nav-link\"&gt;Contact&lt;\/a&gt;\n                            &lt;\/li&gt;\n                        &lt;\/ul&gt;\n                    &lt;\/div&gt;\n                &lt;\/div&gt;\n            &lt;\/nav&gt;\n        );\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/programmingfields.com\/create-rest-api-in-laravel-8-using-jwt-authentication\/\" target=\"_blank\" rel=\"noreferrer noopener\">Create REST API in Laravel 8 Using JWT Authentication<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_Home_About_and_Contact_Component\"><\/span><strong>Create Home, About, and Contact Component<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In rest components put a just title to identify the component. Start from <strong>Home<\/strong> component.<\/p>\n\n\n\n<pre title=\"Home.js\" class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import React, { Component } from 'react';\n\nexport default class Home extends Component {\n    render() {\n        return (\n            &lt;h2 className=\"text-center\"&gt;This is Home page&lt;\/h2&gt;\n        );\n    }\n}<\/code><\/pre>\n\n\n\n<p>Secondly, do the same thing in the <strong>About<\/strong> component.<\/p>\n\n\n\n<pre title=\"About.js\" class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import React, { Component } from 'react';\n\nexport default class About extends Component {\n    render() {\n        return (\n            &lt;h2 className=\"text-center\"&gt;This is About page&lt;\/h2&gt;\n        );\n    }\n}<\/code><\/pre>\n\n\n\n<p>Lastly, for the <strong>Contact<\/strong> component add the same title.<\/p>\n\n\n\n<pre title=\"Contact.js\" class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import React, { Component } from 'react';\n\nexport default class Contact extends Component {\n    render() {\n        return (\n            &lt;h2 className=\"text-center\"&gt;This is Contact page&lt;\/h2&gt;\n        );\n    }\n}<\/code><\/pre>\n\n\n\n<p>I have added a simple heading with a title in the above components.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/programmingfields.com\/how-to-create-github-login-in-laravel-8-using-socialite\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Create Github Login in Laravel 8 Using Socialite<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Render_Components_in_React_JS\"><\/span><strong>Render Components in React JS<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Firstly, import the <strong>Header<\/strong> component only inside the <strong>App<\/strong> component. So that it can be rendered to display the result.<\/p>\n\n\n\n<pre title=\"App.js\" class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import React, { Component } from 'react';\nimport Header from '.\/components\/Header';\n\nclass App extends Component {\n    render() {\n        return (\n          &lt;Header\/&gt;\n        );\n    }\n}\n\nexport default App;<\/code><\/pre>\n\n\n\n<p>Now, switch to the browser and check the result.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"410\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-08-18-21.png?resize=1024%2C410&#038;ssl=1\" alt=\"React JS - Header with Navigation Bar\" class=\"wp-image-6442\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-08-18-21.png?resize=1024%2C410&amp;ssl=1 1024w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-08-18-21.png?resize=300%2C120&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-08-18-21.png?resize=768%2C307&amp;ssl=1 768w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-08-18-21.png?w=1127&amp;ssl=1 1127w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption class=\"wp-element-caption\"><strong>React JS &#8211; Header with Navigation Bar<\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<p>Here, the main issue occurs. How you will add the particular components with their respective navigation links? We have <strong>Home<\/strong>, <strong>About<\/strong>, and <strong>Contact<\/strong> components. Also, we have the navigation link for the same in the header.<\/p>\n\n\n\n<p>If you try rendering the components respectively inside the App component, it will be rendered one after one. Let&#8217;s checkout the result by adding the below code.<\/p>\n\n\n\n<pre title=\"App.js\" class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import React, { Component } from 'react';\nimport Header from '.\/components\/Header';\nimport Home from '.\/components\/Home';\nimport About from '.\/components\/About';\nimport Contact from '.\/components\/Contact';\n\nclass App extends Component {\n    render() {\n        return (\n            &lt;&gt;\n                &lt;Header\/&gt;\n                &lt;Home\/&gt;\n                &lt;About\/&gt;\n                &lt;Contact\/&gt;\n            &lt;\/&gt;\n        );\n    }\n}\nexport default App;<\/code><\/pre>\n\n\n\n<p>Navigate back to the browser and see the result.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"468\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-08-40-56.png?resize=1024%2C468&#038;ssl=1\" alt=\"Multiple Components Rendering in React JS\" class=\"wp-image-6449\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-08-40-56.png?resize=1024%2C468&amp;ssl=1 1024w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-08-40-56.png?resize=300%2C137&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-08-40-56.png?resize=768%2C351&amp;ssl=1 768w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-08-40-56.png?w=1129&amp;ssl=1 1129w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption class=\"wp-element-caption\"><strong>Multiple Components Rendering in React JS<\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<p>Here, you can achieve this using the React Routing concepts. React uses React Router DOM for managing the routes and components linking.<\/p>\n\n\n\n<p>Hence, you need to install the package for it.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/programmingfields.com\/create-login-with-twitter-in-laravel-8-using-socialite\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Create Login with Twitter in Laravel 8 Using Socialite<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Install_React_Router_DOM_in_React_JS\"><\/span><strong>Install React Router DOM in React JS<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To install the <strong>React Router DOM<\/strong>, you need to hit the below command. It will install the latest version.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">npm i&nbsp;react-router-dom<\/code><\/pre>\n\n\n\n<p>Here, the <strong>React Router DOM<\/strong> is installed. Now, we can use it for implementing the React Routes.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"816\" height=\"289\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-56-24.png?resize=816%2C289&#038;ssl=1\" alt=\"Install React Router DOM in React JS\" class=\"wp-image-6432\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-56-24.png?w=816&amp;ssl=1 816w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-56-24.png?resize=300%2C106&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-07-56-24.png?resize=768%2C272&amp;ssl=1 768w\" sizes=\"auto, (max-width: 816px) 100vw, 816px\" \/><figcaption class=\"wp-element-caption\"><strong>Install React Router DOM in React JS<\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Use_of_React_Route\"><\/span><strong>Use of React Route<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>After installing the package, let&#8217;s come to the <strong>App.js<\/strong> component and import some components from <code>react-router-dom<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import { Route, BrowserRouter as Router } from 'react-router-dom';<\/code><\/pre>\n\n\n\n<p>Here, I have imported <strong>Route<\/strong> and <strong>BrowserRouter<\/strong> component.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Here, the <strong>Route<\/strong> will be used to set the URL for a view. Also, it syncs the component with the specified URL.<\/li>\n\n\n\n<li>The <strong>BrowserRouter<\/strong> is aliased as <strong>Router<\/strong>. So, here if you have multiple Routes, then need to wrapped out inside the <strong>BrowserRouter<\/strong>. Here, we created the alias, hence, we can use the <code>&lt;Router&gt;&lt;\/Router&gt;<\/code> component instead of <code>&lt;BrowserRouter&gt;&lt;\/BrowserRouter&gt;<\/code>.<\/li>\n<\/ul>\n\n\n\n<pre title=\"App.js\" class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import React, { Component } from 'react';\nimport Header from '.\/components\/Header';\nimport Home from '.\/components\/Home';\nimport About from '.\/components\/About';\nimport Contact from '.\/components\/Contact';\nimport { Route, BrowserRouter as Router } from 'react-router-dom';\n\nclass App extends Component {\n    render() {\n        return (\n            &lt;Router&gt;\n                &lt;Header\/&gt;\n                    &lt;Route path=\"\/\" component={ Home } \/&gt;\n                    &lt;Route path=\"\/about\" component={ About } \/&gt;\n                    &lt;Route path=\"\/contact\" component={ Contact } \/&gt;\n            &lt;\/Router&gt;\n        );\n    }\n}\nexport default App;<\/code><\/pre>\n\n\n\n<p>In the above code, I have set three routes and wrapped it inside the Router. Now, you can use these routes in the browser URL to load the components. Switch back to the browser and let&#8217;s checkout the result.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Get_Result_of_Using_React_Route\"><\/span><strong>Get Result of Using React Route<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We set the Home component in &#8220;\/&#8221; route. So, when the app will load, it will render the Home component.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"993\" height=\"430\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-11-08-02-1.png?resize=993%2C430&#038;ssl=1\" alt=\"Homepage Rendered By React Route\" class=\"wp-image-6476\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-11-08-02-1.png?w=993&amp;ssl=1 993w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-11-08-02-1.png?resize=300%2C130&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-11-08-02-1.png?resize=768%2C333&amp;ssl=1 768w\" sizes=\"auto, (max-width: 993px) 100vw, 993px\" \/><figcaption class=\"wp-element-caption\"><strong>Homepage Rendered By React Route<\/strong><\/figcaption><\/figure>\n\n\n\n<p>Now, change the route to <code>\/about<\/code> and you will have the <code>Home<\/code> as well as <code>About<\/code> component content.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"404\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-12-20-19.png?resize=1024%2C404&#038;ssl=1\" alt=\"Home and About Component Rendered same time\" class=\"wp-image-6491\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-12-20-19.png?resize=1024%2C404&amp;ssl=1 1024w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-12-20-19.png?resize=300%2C118&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-12-20-19.png?resize=768%2C303&amp;ssl=1 768w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-12-20-19.png?w=1028&amp;ssl=1 1028w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption class=\"wp-element-caption\"><strong>Home and About Component Rendered <\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<p>But, this is not an actual result that we were expecting. We navigated to the <strong>\/about<\/strong> route and it must show load only the About component. This is happening because of route expression doesn&#8217;t check strictly. So, it is treating &#8220;\/&#8221; and &#8220;\/about&#8221; as same. Similarly, it will be for the &#8220;\/contact&#8221;.<\/p>\n\n\n\n<p>So, we need to fix it by adding the attribute named <code>exact<\/code> for the first &#8220;\/&#8221; route.<\/p>\n\n\n\n<pre title=\"Header.js\" class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import React, { Component } from 'react';\nimport Header from '.\/components\/Header';\nimport Home from '.\/components\/Home';\nimport About from '.\/components\/About';\nimport Contact from '.\/components\/Contact';\nimport { Route, BrowserRouter as Router } from 'react-router-dom';\n\nclass App extends Component {\n    render() {\n        return (\n            &lt;Router&gt;\n                    &lt;Header\/&gt;\n                    &lt;Route exact path=\"\/\" component={ Home } \/&gt;\n                    &lt;Route path=\"\/about\" component={ About } \/&gt;\n                    &lt;Route path=\"\/contact\" component={ Contact } \/&gt;\n            &lt;\/Router&gt;\n        );\n    }\n}\nexport default App;<\/code><\/pre>\n\n\n\n<p>Now, the result is expected. It is loaded only About component.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1001\" height=\"432\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-11-08-15-1.png?resize=1001%2C432&#038;ssl=1\" alt=\"About Component\" class=\"wp-image-6473\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-11-08-15-1.png?w=1001&amp;ssl=1 1001w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-11-08-15-1.png?resize=300%2C129&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-11-08-15-1.png?resize=768%2C331&amp;ssl=1 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption class=\"wp-element-caption\"><strong>About Component<\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<p>Similarly, when you will change the route to <code>\/contact<\/code>, it will load the content of the <strong>Contact<\/strong> component.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"998\" height=\"432\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-11-08-28-1.png?resize=998%2C432&#038;ssl=1\" alt=\"Contact Component Content \" class=\"wp-image-6474\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-11-08-28-1.png?w=998&amp;ssl=1 998w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-11-08-28-1.png?resize=300%2C130&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-11-08-28-1.png?resize=768%2C332&amp;ssl=1 768w\" sizes=\"auto, (max-width: 998px) 100vw, 998px\" \/><figcaption class=\"wp-element-caption\"><strong>Contact Component Content <\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<p>Here, as per the every route, component is loaded one by one. Now, we need to set these routes for navigating the components. So, you need to put up these routes for the navigation link respectively.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/programmingfields.com\/create-linkedin-login-in-laravel-8-using-socialite\/\" target=\"_blank\" rel=\"noreferrer noopener\">Create LinkedIn Login in Laravel 8 Using Socialite<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Use_of_Link_Component_in_React_JS\"><\/span><strong>Use of Link Component in React JS<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For creating any clickable link like anchor tag, you will be having the <code>&lt;Link&gt;&lt;\/Link&gt;<\/code> component in React JS. So, in order to navigating component to component, you need to apply it to the Header component inside the Navbar. Let&#8217;s do that.<\/p>\n\n\n\n<p>Firstly, switch to the Header.js file and import the Link component.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import { Link } from 'react-router-dom';<\/code><\/pre>\n\n\n\n<p>After importing the above component, you can use it instead of anchor tag. So, replace all the anchor tag with &lt;Link&gt; from the Header component. <\/p>\n\n\n\n<p>The &lt;Link&gt; component has an attribute named &#8220;to&#8221; for the redirection. So, let&#8217;s checkout the below code.<\/p>\n\n\n\n<pre title=\"Header.js\" class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import React from 'react';\nimport { Link } from 'react-router-dom';\n\nexport default class Header extends React.Component {\n    render() {\n        return (\n            &lt;nav className=\"navbar navbar-expand-lg navbar-dark bg-dark sticky-top\"&gt;\n                &lt;div className=\"container\"&gt;\n                    &lt;Link to=\"\/\" className=\"navbar-brand\"&gt;Programming Fields&lt;\/Link&gt;\n                    &lt;button className=\"navbar-toggler\" type=\"button\" data-bs-toggle=\"collapse\" data-bs-target=\"#navbarNavAltMarkup\" aria-controls=\"navbarNavAltMarkup\" aria-expanded=\"false\" aria-label=\"Toggle navigation\"&gt;\n                        &lt;span className=\"navbar-toggler-icon\"&gt;&lt;\/span&gt;\n                    &lt;\/button&gt;\n                    &lt;div className=\"collapse navbar-collapse\" id=\"navbarNavAltMarkup\"&gt;\n                        &lt;ul className=\"navbar-nav m-auto\"&gt;\n                            &lt;li className=\"navbar-item\"&gt;\n                                &lt;Link to=\"\/\" className=\"nav-link\" aria-current=\"page\"&gt;Home&lt;\/Link&gt;\n                            &lt;\/li&gt;\n                            &lt;li className=\"navbar-item\"&gt;\n                                &lt;Link to=\"\/about\" className=\"nav-link\"&gt;About Us&lt;\/Link&gt;\n                            &lt;\/li&gt;\n                            &lt;li className=\"navbar-item\"&gt;\n                                &lt;Link to=\"\/contact\" className=\"nav-link\"&gt;Contact&lt;\/Link&gt;\n                            &lt;\/li&gt;\n                        &lt;\/ul&gt;\n                    &lt;\/div&gt;\n                &lt;\/div&gt;\n            &lt;\/nav&gt;\n        );\n    }\n}<\/code><\/pre>\n\n\n\n<p>Move back to the browser and check the result. This time, you will be having the redirection through the navigation bar for all components.<\/p>\n\n\n\n<p>But, here something is missed. What if you want to set some style on the active navigation? <\/p>\n\n\n\n<p>We have the another component in React that is <code>&lt;NavLink&gt;<\/code>. Let&#8217;s see the usage.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/programmingfields.com\/create-login-with-google-using-socialite-in-laravel-8\/\" target=\"_blank\" rel=\"noreferrer noopener\">Create Socialite Login with Google Account in Laravel 8<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Use_NavLink_Component_in_React_For_Active_Link\"><\/span><strong>Use NavLink Component in React For Active Link<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you are creating a plain link just for anchor then you might use the Link component. But, when you are creating Navigation for the header or something like that then you must use the <strong>NavLink<\/strong> component.<\/p>\n\n\n\n<pre title=\"Header.js\" class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import React from 'react';\nimport { NavLink } from 'react-router-dom';\n\nexport default class Header extends React.Component {\n    render() {\n        return (\n            &lt;nav className=\"navbar navbar-expand-lg navbar-dark bg-dark sticky-top\"&gt;\n                &lt;div className=\"container\"&gt;\n                    &lt;NavLink to=\"\/\" className=\"navbar-brand\"&gt;Programming Fields&lt;\/NavLink&gt;\n                    &lt;button className=\"navbar-toggler\" type=\"button\" data-bs-toggle=\"collapse\" data-bs-target=\"#navbarNavAltMarkup\" aria-controls=\"navbarNavAltMarkup\" aria-expanded=\"false\" aria-label=\"Toggle navigation\"&gt;\n                        &lt;span className=\"navbar-toggler-icon\"&gt;&lt;\/span&gt;\n                    &lt;\/button&gt;\n                    &lt;div className=\"collapse navbar-collapse\" id=\"navbarNavAltMarkup\"&gt;\n                        &lt;ul className=\"navbar-nav m-auto\"&gt;\n                            &lt;li className=\"navbar-item\"&gt;\n                                &lt;NavLink to=\"\/\" className=\"nav-link\"&gt;Home&lt;\/NavLink&gt;\n                            &lt;\/li&gt;\n                            &lt;li className=\"navbar-item\"&gt;\n                                &lt;NavLink to=\"\/about\" className=\"nav-link\"&gt;About Us&lt;\/NavLink&gt;\n                            &lt;\/li&gt;\n                            &lt;li className=\"navbar-item\"&gt;\n                                &lt;NavLink to=\"\/contact\" className=\"nav-link\"&gt;Contact&lt;\/NavLink&gt;\n                            &lt;\/li&gt;\n                        &lt;\/ul&gt;\n                    &lt;\/div&gt;\n                &lt;\/div&gt;\n            &lt;\/nav&gt;\n        );\n    }\n}<\/code><\/pre>\n\n\n\n<p>Now, check the result. Here, you can see the About Us link is active and it&#8217;s content is loaded. Also, you can check the elements by inspecting it. Here, for the about link there is an <strong>active<\/strong> class.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"454\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-12-08-11.png?resize=1024%2C454&#038;ssl=1\" alt=\"Use of NavLink in React Routes For Active Class\" class=\"wp-image-6486\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-12-08-11.png?resize=1024%2C454&amp;ssl=1 1024w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-12-08-11.png?resize=300%2C133&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-12-08-11.png?resize=768%2C341&amp;ssl=1 768w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-12-08-11.png?w=1069&amp;ssl=1 1069w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption class=\"wp-element-caption\"><strong>Use of NavLink in React Routes For Active Class<\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<p>This is only difference of using <code>Link<\/code> and <code>NavLink<\/code> component in React JS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conflict_of_Having_Multiple_Same_Routes\"><\/span><strong>Conflict of Having Multiple Same Routes<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Sometimes you have multiple routes with the same path but different components. Let me show you an example. Here, I have created one more component named <strong>Services.js<\/strong>. <\/p>\n\n\n\n<p>Then imported it inside the <strong>App<\/strong> component. Inside the &lt;Router&gt;&lt;\/Router&gt;, we already created some <strong>React Routes<\/strong>. Now, add one more route as showing below.<\/p>\n\n\n\n<pre title=\"App.js\" class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import React, { Component } from 'react';\nimport Header from '.\/components\/Header';\nimport Home from '.\/components\/Home';\nimport About from '.\/components\/About';\nimport Contact from '.\/components\/Contact';\nimport Services from '.\/components\/Services';\nimport { Route, BrowserRouter as Router } from 'react-router-dom';\n\nclass App extends Component {\n    render() {\n        return (\n            &lt;Router&gt;\n                    &lt;Header\/&gt;\n                    &lt;Route exact path=\"\/\" component={ Home } \/&gt;\n                    &lt;Route path=\"\/about\" component={ About } \/&gt;\n                    &lt;Route path=\"\/about\" component={ Services } \/&gt;\n                    &lt;Route path=\"\/contact\" component={ Contact } \/&gt;\n            &lt;\/Router&gt;\n        );\n    }\n}\nexport default App;<\/code><\/pre>\n\n\n\n<p>Here, I have added one more route with the <code>path=\"\/about\"<\/code>. But, added different component that is <strong>Services<\/strong>.<\/p>\n\n\n\n<p>Check the result to get a clear understanding. In the result, you can see both components are rendered because of same <strong>path<\/strong> in React Route.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"387\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-13-09-50.png?resize=1024%2C387&#038;ssl=1\" alt=\"React Routes Rendered Multiple Components\" class=\"wp-image-6494\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-13-09-50.png?w=1024&amp;ssl=1 1024w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-13-09-50.png?resize=300%2C113&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-13-09-50.png?resize=768%2C290&amp;ssl=1 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption class=\"wp-element-caption\"><strong>React Routes Rendered Multiple Components<\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<p>We used the <strong>&lt;Router&gt;<\/strong> for wrapping the <strong>React Routes<\/strong>. So when you navigate to the route, the React Router DOM searches all the routes from the list one by one. It renders the component on the matching of the path. So, here it founds two<strong> <\/strong>routes with the same path. Hence, it rendered both.<\/p>\n\n\n\n<p>In case, if you have these kind of issue then you can fix it by using <strong>&lt;Switch&gt;<\/strong> component in Rect JS.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/programmingfields.com\/how-to-create-facebook-login-in-laravel-8-using-socialite\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Create Facebook Login in Laravel 8 Using Socialite<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Use_of_Switch_Component_in_React_JS\"><\/span><strong>Use of Switch Component in React JS<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The <strong>Switch<\/strong> component works really like a switch case in JavaScript or other languages. When you put up the routes inside the <strong>&lt;Switch&gt;&lt;\/Switch&gt;<\/strong> component, it will check the request path and render only the first match. Once the match found, it won&#8217;t continue the search for the next routes.<\/p>\n\n\n\n<p>In order to use the <strong>&lt;Switch&gt;<\/strong> component, you need to import it first.<\/p>\n\n\n\n<pre title=\"App.js\" class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import React, { Component } from 'react';\nimport Header from '.\/components\/Header';\nimport Home from '.\/components\/Home';\nimport About from '.\/components\/About';\nimport Contact from '.\/components\/Contact';\nimport Services from '.\/components\/Services';\nimport { Route, BrowserRouter as Router, Switch } from 'react-router-dom';\n\nclass App extends Component {\n    render() {\n        return (\n            &lt;Router&gt;\n                  &lt;Header\/&gt;\n                  &lt;Switch&gt;\n                      &lt;Route exact path=\"\/\" component={ Home } \/&gt;\n                      &lt;Route path=\"\/about\" component={ About } \/&gt;\n                      &lt;Route path=\"\/about\" component={ Services } \/&gt;\n                      &lt;Route path=\"\/contact\" component={ Contact } \/&gt;\n                  &lt;\/Switch&gt;\n            &lt;\/Router&gt;\n        );\n    }\n}\nexport default App;<\/code><\/pre>\n\n\n\n<p>In the result, you will having only the first match of the route path that is About. So, it rendered only About page content.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"491\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-13-23-11.png?resize=1024%2C491&#038;ssl=1\" alt=\"About Component Rendered Using Switch Component\" class=\"wp-image-6496\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-13-23-11.png?resize=1024%2C491&amp;ssl=1 1024w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-13-23-11.png?resize=300%2C144&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-13-23-11.png?resize=768%2C368&amp;ssl=1 768w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/Screenshot-from-2021-06-19-13-23-11.png?w=1026&amp;ssl=1 1026w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption class=\"wp-element-caption\"><strong><strong>About Component Rendered Using Switch Component<\/strong><\/strong><\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><strong>Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Finally, we digged deep in <strong>React Router DOM<\/strong> for creating and managing <strong>React Routes<\/strong>. It is not completed in this one post. I tried to cover the important points but many more are left. We will see in the next post and more in the upcoming posts in the React series. So, I hope you got the concept of using the <strong>React Router, BrowserRouter, Link, NavLink, Switch etc.<\/strong> Stay in touch with us for diving more in the React world. Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Do you want to handle and render multiple components in React? If yes then this post is only for you. Yeah, I am talking about navigating from component to component. While navigating to components the page doesn&#8217;t refresh in React. Also, it needs to change the route dynamically. If you render the child components in [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":6499,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1369],"tags":[2117,2113,2115,2118,2112,2110,2108,2116],"yst_prominent_words":[1684,1401],"class_list":{"0":"post-6403","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-react","8":"tag-react-component-navigation","9":"tag-react-components","10":"tag-react-navlink","11":"tag-react-navlink-path","12":"tag-react-router-dom","13":"tag-react-routes","14":"tag-react-routing","15":"tag-react-switch","16":"entry"},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2021\/06\/React-Router-DOM.png?fit=2240%2C1260&ssl=1","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/posts\/6403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/comments?post=6403"}],"version-history":[{"count":2,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/posts\/6403\/revisions"}],"predecessor-version":[{"id":8937,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/posts\/6403\/revisions\/8937"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/media\/6499"}],"wp:attachment":[{"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/media?parent=6403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/categories?post=6403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/tags?post=6403"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/yst_prominent_words?post=6403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}