router react tutorial

npm install react-router-dom

4.4
5

                                    function Navbar() {
  return (
    <div>
      <Link to="/">Home </Link>
      <Link to="/about">About Us </Link>
      <Link to="/shop">Shop Now </Link>
    </div>
  );
};

4.4 (5 Votes)
0
3.5
4

                                    //App.js File
import React from 'react';
import {BrowserRouter, Switch, Route} from 'react-router-dom';
import Navbar from './Navbar';
import About from './About';
import Shop from './Shop';

//all classNames beginning with w3-* are from w3.css framework available on w3.schools.com
export default class App extends React.Component {
    render() {
        return (
            <BrowserRouter>
                <div className="w3-container">
                    <Navbar />
                    <Switch>
                        <Route path="/about" exact component={About}/>
                        <Route path="/shop" exact component={Shop}/>
                    </Switch>
                </div>
            </BrowserRouter>
        )
    }
}

//Navbar.js File
import React from 'react';
import {Link} from 'react-router-dom';

export default class Navbar extends React.Component{
    render(){
    return(
        <div className="w3-bar w3-deep-purple">
            <span className="w3-bar-item w3-button w3-hover-green">MyReactRouter</span>
            <Link to="/about" className="w3-bar-item w3-button w3-hover-green">
                <span>About</span>
            </Link>
            <Link to="/shop">
                <span className="w3-bar-item w3-button w3-hover-green">Shop</span>
            </Link>
        </div>
    )
    }
}

//About.js File
import React from 'react';
export default function About(){
    return(
        <div className="w3-container">
            <h1 className="w3-header w3-indigo w3-center">About Page</h1>
        </div>
    )
}

//Shop.js File
import React from 'react';
export default function Shop(){
    return(
        <div className="w3-container">
            <h1 className="w3-header w3-indigo w3-center">Shop Page</h1>
        </div>
    )
}

3.5 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
router in react-router-dom tutorial react router React Router Tutorial | React For Beginners react router easy tutorial learn about how to router in react react router and react router dom react-router-dom react simple react router tutorial routes tutorial in react react-router dom routing react tutorial reactjs router dom reactjs router tutorial react react-router-dom react routes tutorial react dom router tutorial react js router tutorial react routing tutorial react router dom tutorial react router dom react router basics react router tutorials react js route tutorial react router -dom react router tutorial router dom react react router react-router-dom" react-router-dom documentation Router react-router-dom react dom router react dom and react router dom react router dom router react dom what is component react router dom react-router-dom package. react Router Dom Route hoc routing in react js react router switch ke router react tutorial react training react router user react-router-dom react router-dom how to make page route in react js what is react dom router react dom and reeact dom router react router component example how to install react router dom rreact router react router docs react router dom docs react router how to install react router dom create react app react router dom how to set path in route reactjs import react router routing in react react route dom route react router dom path route react router dom using react router react router dom proper pathing react router documentation react router dom vs a li routes react js react router examples react routers react router dom install react router dom documentation react router example <router> react routr install react router router reactjs how to make routes in array react router dom react routing react route router react imp switch react router webpage usingreact router web page using react-dom-router package for routing/linking these components. react-router-dom
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source