<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sunny</title>
    <description>The latest articles on DEV Community by Sunny (@eladossa).</description>
    <link>https://dev.to/eladossa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F659067%2Fdadbaf50-996b-433a-b5ce-0ce84affcddf.png</url>
      <title>DEV Community: Sunny</title>
      <link>https://dev.to/eladossa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eladossa"/>
    <language>en</language>
    <item>
      <title>How to navigate and switch components with BrowserRouter</title>
      <dc:creator>Sunny</dc:creator>
      <pubDate>Wed, 30 Jun 2021 09:41:08 +0000</pubDate>
      <link>https://dev.to/eladossa/how-to-navigate-and-switch-components-with-browserrouter-3k14</link>
      <guid>https://dev.to/eladossa/how-to-navigate-and-switch-components-with-browserrouter-3k14</guid>
      <description>&lt;p&gt;I want to switch between components after the user entered the requested info. &lt;br&gt;
&lt;br&gt; Components that will be shown to user by this order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;{MobileNum } Enter mobile number&lt;/li&gt;
&lt;li&gt;{IdNumber } ID number&lt;/li&gt;
&lt;li&gt;{CreatePassword } Create Password&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When all these steps are completed the browser will switch to the home page.&lt;br&gt;
The first time user must &lt;strong&gt;not be able&lt;/strong&gt; to move between pages until he filled each request.&lt;/p&gt;

&lt;p&gt;Without using &lt;code&gt;*React Router*&lt;/code&gt; I used to switch only two components with a conditional rendering  &lt;/p&gt;

&lt;p&gt;Now I definitely want a better way with &lt;code&gt;BrowserRouter&lt;/code&gt; as if I had 3-4 components inside &lt;code&gt;Login&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { Component } from 'react';
import {
  BrowserRouter as Router,
  Redirect,
  Route,
  Switch,
} from 'react-router-dom';
import MobileNum from './MobileNum.jsx';
import IdentNumber from './IdNum.jsx';
import CreatePassword from './createPassword .jsx';

class Login extends Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      &amp;lt;div&amp;gt;
        &amp;lt;Router&amp;gt;
          &amp;lt;Switch&amp;gt;
            &amp;lt;Route path='/'  component={MobileNum} /&amp;gt;                                                
            &amp;lt;Route path='/'  component={IdNum} /&amp;gt;
            &amp;lt;Route path='/'  component={CreatePassword } /&amp;gt;
          &amp;lt;/Switch&amp;gt;
        &amp;lt;/Router&amp;gt;
      &amp;lt;/div&amp;gt;
    );
  }
}

export default Login;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I searched the web in &lt;em&gt;reactrouter.com&lt;/em&gt; and many others as here for a clean solution but found no answer.&lt;br&gt;
&lt;br&gt; &lt;strong&gt;Any Idea what's the best way to do it ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>question</category>
      <category>browserrouter</category>
      <category>navigation</category>
    </item>
  </channel>
</rss>
