This project is a simple React application created to learn and explore the basics of routing using react-router-dom. It implements dynamic routes, nested routing, route loaders, and more to provide a hands-on understanding of React Router.
- Nested Routing: Demonstrates the use of nested routes with shared layouts.
- Dynamic Routing: Showcases how to use dynamic parameters in routes (e.g.,
/user/:userID). - Route Loaders: Integrates loaders for data fetching before rendering a component (e.g., GitHub component).
- Component Structure: Organized components for modular and reusable code.
src/
├── components/
│ ├── About/
│ │ └── About.jsx
│ ├── Contact/
│ │ └── Contact.jsx
│ ├── GitHub/
│ │ ├── GitHub.jsx
│ │ └── githubInfoLoader.js
│ ├── Home/
│ │ └── Home.jsx
│ └── User/
│ └── User.jsx
├── Layout.jsx
├── main.jsx
├── index.css
└── index.html
- React: Front-end library for building user interfaces.
- React Router DOM: Library for implementing routing in React.
- JavaScript (ES6+): Modern syntax for developing the application.
- CSS: For basic styling.
-
Browser Router Setup
- Used
createBrowserRouterto configure routes. - Demonstrated two approaches for defining routes:
- Array-based configuration.
- JSX-based route creation using
createRoutesFromElements.
- Used
-
Nested Routes
- Organized routes under a common layout component (
Layout.jsx).
- Organized routes under a common layout component (
-
Dynamic Routes
- Implemented a route with dynamic parameters (
/user/:userID).
- Implemented a route with dynamic parameters (
-
Route Loaders
- Utilized
loaderfor data fetching before rendering a route (/github).
- Utilized
-
Clone the repository:
git clone https://github.com/imshashwatsingh/React-Router-Project.git cd React-Router-Project -
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
Open your browser and visit
http://localhost:5173to explore the app.
| Path | Component | Description |
|---|---|---|
/ |
Home |
Displays the home page. |
/about |
About |
Displays information about the app. |
/contact |
Contact |
Provides a contact form/page. |
/user/:userID |
User |
Displays user-specific information dynamically. |
/github |
GitHub |
Displays GitHub info with preloaded data. |
- Add more examples of route guards (protected routes).
- Implement advanced data fetching with custom hooks.
- Explore animations during route transitions.
- Introduce error boundaries for handling route errors.
Feel free to fork this project and submit pull requests to enhance it or report issues.
This project is open source and available under the MIT License.
This project was built as part of a learning exercise to explore the features of react-router-dom. Special thanks to the React community for providing amazing resources and documentation.