React With Routing
React Router is a popular library for handling navigation in React applications. It enables the creation of single-page applications with navigation that feels like a traditional multi-page website. React Router provides a set of navigational components and a declarative approach to define the routes of your application.
How To Setup React Router Package
npm i react-router-dom@7
Setup BrowserRouter
- < StrictMode >
- < BrowserRouter >
- < App />
- < /BrowserRouter >
- < /StrictMode >
Tools to Set Up a React App
- < Routes >
- < Route path="/" element={< Home />} />
- < Route path="/page" element={< Page />} />
- < Route path="/profile" element={< Profile />} />
- < Route path="*" element={< h1 >Page 404< /h1 >} />
- < Routes >
When to Use React.js
- You want maximum flexibility and control over your project.
- You are building a highly interactive single-page application (SPA).
- You are comfortable setting up your own routing, state management, and other tools.