Nearby lessons

33 of 43

🛣️ ReactJS – Dynamic Routes

📌 What are Dynamic Routes?

Dynamic Routes in React Router

React Router supports two types of routing:

  1. Static Routing: Routes are defined in a centralized location before rendering.
  2. Dynamic Routing: Routes are initialized dynamically at runtime, when the page gets rendered.

Note: Give priority first to static routes, then dynamic routes.

📌 Static Routing

In static routing, all routes are declared in a centralized file (e.g., App.jsx). These routes are loaded before the application starts rendering.

⚡ Dynamic Routing

In dynamic routing, the routing configuration is defined as components render. Routes can include dynamic parameters such as :id for user profiles, product details, etc.

Example03
Loading editor…

📌 Sorting Technique for Dynamic Routes

Dynamic routes should be declared after static routes. Otherwise, React Router may match dynamic parameters before static ones.

For example, always declare /users/admin before /users/:id.

Example04
Loading editor…

🧠 Test Your Knowledge

4 Questions
Progress: 0 / 4