<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sharifa  Al-abry on Medium]]></title>
        <description><![CDATA[Stories by Sharifa  Al-abry on Medium]]></description>
        <link>https://medium.com/@sharifataimur219?source=rss-2d588d1cf934------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NF0fwt5qSow2AnPWWxw8Zw@2x.jpeg</url>
            <title>Stories by Sharifa  Al-abry on Medium</title>
            <link>https://medium.com/@sharifataimur219?source=rss-2d588d1cf934------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 19:01:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sharifataimur219/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Route, Router & Link in React]]></title>
            <link>https://sharifataimur219.medium.com/route-router-link-in-react-cc5ea5c10a78?source=rss-2d588d1cf934------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc5ea5c10a78</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[routing]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[router]]></category>
            <category><![CDATA[route]]></category>
            <dc:creator><![CDATA[Sharifa  Al-abry]]></dc:creator>
            <pubDate>Thu, 19 Nov 2020 10:42:05 GMT</pubDate>
            <atom:updated>2020-11-19T10:45:21.833Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Router, Route &amp; Link in React</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_FqxNXqzjXLdBis8" /><figcaption>Photo by <a href="https://unsplash.com/@lazizli?utm_source=medium&amp;utm_medium=referral">Lala Azizli</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>When I first started learning React, I had a major confusion of how to use Route, Router &amp; Link. What are they? And how do they connect to each other? And most importantly how do we implement them into our projects.</strong></p><p><strong>Below I have mentioned points &amp; explanations to help absolute beginners understand each of these.</strong></p><ol><li>First step you need to install:</li></ol><pre>npm install react-router-dom --save</pre><p>2. Then we need to import <strong>BrowserRouter</strong>, <strong>Route</strong>, and <strong>Link </strong>from <strong>react-router-dom</strong> :</p><pre>import {BrowserRouter as Router,Switch,Route} from &#39;react-router-dom&#39;;</pre><p>3. Now we need to wrap everything that is inside the return function with <strong>&lt;Router&gt;</strong> like below , What does <strong>&lt;Router&gt;</strong> do?</p><ul><li>React Router allows us to build single-page web applications with navigation without page refresh as the user navigates through the application. It is said to be:</li></ul><blockquote>“React Router keeps your UI in sync with the URL. It has a simple API with powerful features like lazy code loading, dynamic route matching, and location transition handling built right in. Make the URL your first thought, not an after-thought.” -<a href="https://www.freecodecamp.org/">https://www.freecodecamp.org</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*xt1PQjJUqPNAwfPy0AJ8vg.png" /></figure><p>4. <strong>Next we add &lt;Switch&gt;</strong>,<strong> Why do we need this?</strong></p><ul><li>The advantage of using <strong>&lt;Switch&gt;</strong> is that it will ONLY render the first route that matches/includes the path. When the first route that matches the path is found, the search will stop (won’t go through all the other <strong>&lt;Routes&gt;</strong>).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*gnGVzfhA3dYrFBBslXl8HQ.png" /></figure><p>5. <strong>After &lt;Switch&gt; we add the &lt;Route&gt;, What is &lt;Route&gt;?</strong></p><ul><li><strong>&lt;Route&gt;</strong> renders component based on specified path. As seen below a Route with the path=”/Login” will only render the Login component.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*NwtbKBWyy2nJbWIKN2-FIg.png" /></figure><p>6. <strong>Next, we need to add &lt;Link&gt;, but what is &lt;Link&gt; used for?</strong></p><ul><li>The <strong>&lt;Link&gt;</strong> component is used to navigate to a specific route <strong>path</strong> that we specified in <strong>&lt;Route&gt;.</strong></li><li>As you can see in the image below, I’m currently in the Login Component of my application.</li><li>The <strong>to=”/”</strong> in the <strong>&lt;Link&gt;</strong> specifies the URL path to which you want the page to redirect to.</li></ul><blockquote>*Note: In the below code you can see that the value of <strong>to=”/” </strong>will render my &lt;Home&gt; &amp; &lt;Header&gt; component. How do we know this? In my previous image (point #5) you will see that there are two components &lt;Header&gt; &amp; &lt;Home&gt; that are wrapped within a &lt;Route <strong>path=”/”</strong>&gt;.So in order for the right components to be rendered the <strong>to=”/” </strong>value in &lt;Link&gt; and the <strong>path=”/”</strong> value in the &lt;Route&gt; should be the same.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HCsoerToImaBI9N3IZj2xg.png" /></figure><p>That’s it! We have successfully implemented routing into our React application. With this method we have added navigation without the need of page refresh when a user clicks on a specific Route.</p><p><strong><em>Thanks for reading! If you have found this article useful, hit the 👏 button to help others find it. Your responses are also highly appreciated. You can also follow me on </em></strong><a href="https://twitter.com/sharifa_alabry"><strong><em>Twitter</em></strong></a><strong><em>, or find me on </em></strong><a href="https://www.linkedin.com/in/sharifa-al-abry-575510119/"><strong><em>LinkedIn</em></strong></a><strong><em>.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc5ea5c10a78" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>