React Routing
Web Technology
Rourab Paul, Subin Sahayam, Assistant Professor,
Department of Computer Science and Engineering
Shiv Nadar University
Front End Development Tasks
K1
React Router
K1
React Router
K2
React Router
K1
React Router is primarily for internal routing within a React application.
Multi-Page Applications
K2
Single Page Applications
K2
React Router
K1
Need for React Router
Enables navigation between different views within a React application.
Utilizes the browser's History API
BrowserRouter, Routes, Route, Link, NavLink
K1
React Router - Packages
K1
React Router - Packages
K1
React Router - Packages
K1
React Router - Packages
K1
React Router - Packages
K1
React Router – Simple Routing
K2
React Router Steps
K1
Simple Routing
K3
Simple Routing
Step 1 — Go to your working folder
Open the terminal and run:
cd /home/rourab/WebTech_lab
K3
Simple Routing
Step 2 — Create a new React project
Run:
npm create vite@latest react-routing-example -- --template react
K3
It will ask some questions. If prompted, choose React and JavaScript.
Then enter the project:
cd react-routing-example
Simple Routing
Step 3 — Install the dependencies
Run:
npm install
Then install React Router:
npm install react-router-dom@latest
K3
Simple Routing
Step 4 — Start the project once
Run:
npm run dev
You should see something similar to:
Local: http://localhost:5173/
Open that URL.
You will initially see the default Vite React page. That's normal.
K3
Simple Routing
Step 5 — Create our routing structure
Now your project should look like:
K3
react-routing-example/
│
├── package.json
├── index.html
├── vite.config.js
│
└── src/
├── App.jsx
├── main.jsx
├── App.css
├── index.css
└── assets/
We will change it to:
react-routing-example/
│
├── package.json
├── index.html
├── vite.config.js
│
└── src/
├── App.jsx
├── main.jsx
├── style.css
│
└── pages/
├── Home.jsx
├── About.jsx
└── Contact.jsx
Simple Routing
Step 6 — Download sample code
paste the pages inside src directory
replace App.jsx, main.jsx and style.css in src directory
run
npm run dev
K3
Advantages of React Router
References
THANK YOU