Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

what is router in react

React router as a browserRouter in App.js for navbar links like Home,
services,conatct-us etc.
   // npm install react-router-dom

// ##### Basic Routing #####
import React from 'react';
import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom';

export default function App() {
   return (
      <Router>
         <div>
            <nav>
               <ul>
                  <li>
                     <Link to="/">Home</Link>
                  </li>
                  <li>
                     <Link to="/about">About</Link>
                  </li>
                  <li>
                     <Link to="/users">Users</Link>
                  </li>
               </ul>
            </nav>

            {/* A <Switch> looks through its children <Route>s and
            renders the first one that matches the current URL. */}
            <Switch>
               <Route path="/about">
                  <About />
               </Route>
               <Route path="/users">
                  <Users />
               </Route>
               <Route path="/">
                  <Home />
               </Route>
            </Switch>
         </div>
      </Router>
   );
}

function Home() {
   return <h2>Home</h2>;
}

function About() {
   return <h2>About</h2>;
}

function Users() {
   return <h2>Users</h2>;
}
Comment

router in react

import {
    BrowserRouter as Router,
    Routes,
    Route,
    Link
} from 'react-router-dom';
Comment

PREVIOUS NEXT
Code Example
Javascript :: react-router react-router-dom 
Javascript :: react-router 
Javascript :: how to see if the window has focus in js 
Javascript :: node convert buffer to string 
Javascript :: format date month day year javascript 
Javascript :: map function in react 
Javascript :: cra redux 
Javascript :: forach loop in javascript 
Javascript :: add key vakue to front of object 
Javascript :: react parameter value from query string 
Javascript :: bootstrap icons react 
Javascript :: all inputs under div 
Javascript :: javascript cookie expire in 5 minutes 
Javascript :: declare empty object javascript 
Javascript :: rect p5js 
Javascript :: how to change the choose file button text in react 
Javascript :: any click event jquery 
Javascript :: alpine in laravel mix 
Javascript :: jquery selector this and class 
Javascript :: click outside react component 
Javascript :: javascript return longest string in array 
Javascript :: permutation javascript 
Javascript :: mui switch colours 
Javascript :: js escape html 
Javascript :: a function that calls itself js 
Javascript :: how to add alternate image in img tag in react 
Javascript :: js map add property 
Javascript :: factorial in javascript 
Javascript :: como ler um arquivo json com javascript 
Javascript :: bootstrap 5.1 3 tooltip not working 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =