Podcast Lookup

React Router DOM Explained | Master Navigation and Routing in React JS

ReactJS Developers Podcast

  • December 3, 2026
  • 1 h 28 min
  • Episode 30
Episode page
About this episodeNavigation is an essential part of building modern web applications. React Router DOM makes it possible to create multi-page experiences…
Navigation is an essential part of building modern web applications. React Router DOM makes it possible to create multi-page experiences in React without requiring a full browser page reload whenever users navigate between different sections of an application.In this episode, you'll learn how to implement routing in React JS using React Router DOM. We'll explore how to configure routes, navigate between pages, create dynamic routes, and build a structured application with multiple views.Whether you're building a portfolio website, dashboard, E-Commerce platform, or any other React application, understanding React Router DOM will help you create better navigation experiences.What You'll Learn
  • What React Router DOM is and why it is important.

  • Installing and configuring React Router DOM.

  • Understanding browser-based routing in React.

  • Setting up routes using BrowserRouter.

  • Creating application routes with Routes and Route.

  • Navigating between pages using Link and NavLink.

  • Using useNavigate for programmatic navigation.

  • Passing URL parameters with dynamic routes.

  • Accessing route parameters using useParams.

  • Creating nested routes and layouts.

  • Handling undefined routes with a 404 page.

  • Organising navigation in a React application.

Who Should Watch?
  • Beginners learning React JS.

  • Frontend developers building multi-page React applications.

  • JavaScript developers transitioning to React.

  • Developers creating dashboards, E-Commerce platforms, and web portals.

  • Students preparing for professional React development.

Transcript

From the publisher

This transcript comes from the podcast’s own feed, shown as the publisher wrote it.

React Router DOM Explained | Master Navigation and Routing in React JS

00:00—
  1. Speaker 1

    So in this part, we are going to discuss React Router DOM and I will also tell you about the old version of React Router DOM and also the newer version syntax. And it is very easy, you will understand it very easily and let's start understanding it directly from the course. For this, you don't need to read a lot of theory. It will be understood very easily, it is also easy. So first of all, you create your own project. I have already installed the Vite project. All the things are set up. I have installed Tailwind CSS because I will make some designs in it. So it will feel good to understand. So you also install Tailwind CSS. Although you want to work on normal CSS here, you can also do it from here. I don't have any problem. But if you do it, it's better. You will keep writing your class name here and your work will continue. And I have taught all this. Now let's understand why we need React Router DOM. You must have seen, heard, written and coded the anchor tag. Our anchor tag looks like this. Here we are basically giving our path or route. Here I give a slash and basically I want to render the home. And in the same way, I make more anchor tags here. Basically, they are creating a link. You have also done this with normal HTML, CSS, and JavaScript. Right? To go to multiple pages, if you want to go to the home page, then you have to go to the slash home, if you want to go to the about page, then you have to go to the slash about. So, you have done this kind of things. So, you should not feel any surprise by seeing it. It is normal HTML work. So, home is done, about is done, contact is done. And along with that, we also make a help page here. Home. About, A-B-O-U-T, About. And how am I writing about? About. Then here you have contact. And last you have help. So I have created some links. And actually let's make it in a component. Let's make it a component named navbar. Okay. New folder. Here we will put all the things in the components. So that it is a little organized. A little, not much organized. Now you have to understand. So let's make a navbar.jsx here. I am doing all these things quickly because you know all these things. So I will cut it from here and go to the navbar and paste it here. Now I will paste this navbar here. You should not have any problem. This is our navbar and remove this h1. What will navbar do here? This is our map bar and it looks very bad because we have done some default styling here. So let's come to index.css and see what style is here. In the body, this display is the place item center. So remove it. And here you see, it will come from above in this way. And do one thing. Do we need all these styles? Think for yourself. Do we need all these styles? We need a button or something. Okay. In the body, this flex or something. Minimum height, minimum width. We don't need to give all this. Remove this body style. And come here and see how it looks. And we have zoomed a little. Isn't it? Now you will get to know how it looks. Let's go to app bar. Class name and bg red 500. So you will get to know how it looks. There is a little margin here. So let's go to index.css. So we have removed everything and there is nothing extra here. And let's see if we get anything else. There will be something in app.css. So, here in the root, margin etc. is given here in the root. We don't need all of this yet. Remove all of this from here. So, see, it is completely stuck on the top. And let's leave the rest. Because there will be no need to style the buttons. There is a style of buttons here in index.css. So, you can see according to yourself whether you want to keep this style or not. You are getting the style. Right? So, in index.css, we removed what we had to remove. And what was to be attached is attached. There is no issue. So, here we have a navbar... It has been created a little dirty. Let's give it light green. Let's see how it looks. And here it looks something like this. Let's zoom it a little. So if we zoom it, then there will be no need to style the font. And you are not knowing the color of the link that something looks so dirty. By default, it will have to be customized. And have they done it in index.css? Search for anchor tag. Yes, it has given color. And even if it has given color, then what kind of dirty color did it give? It shouldn't have given such a dirty color. It's okay. It's better now. And let's do one thing. Let's do tomato when we hover. It should feel a little. It's fun, isn't it? Look at this. And by default, it's white. So it's not a problem. It's looking good now. It's looking much better now. Now let's style it a little. here we will display flex and give a gap of 5, so this will be a little gap, so help page, contact page, about page, home page has been created and if you observe carefully here, observe carefully, as I click on home, the page is reloading, see here at this place, I can't zoom this, so I will edit it and zoom it and show you, although you can focus a little, you can zoom yourself, As I click on home, the whole page is reloaded. As I click on about page, the whole page is reloaded. We know that there is no concept of reloading in react. We don't load the whole content together. We need to change as much as the part changes. So this whole page is being asked to refresh. This is a little wrong manner of working here. This was a normal HTML CSS work. Exactly this way we don't have to do it here. I am clicking on about and it is reloading. Means the whole page is coming back. I am clicking on contact and the whole page is reloading. Means the whole content will come back. So somewhere performance wise it is not that good. So here we will do something so that the page is not reloaded. Our react's virtual down concept is that we have to change only that much part. We will use react-router-dom for this. To avoid this, we are not going to use normal anchor tag. We are going to use react-router-dom. You can search react-router-dom As you can see, you will get your first site of react-router-dom. This is the site of NPM, but you will not get any special documentation in it. If you want to read the documentation, then you can go to react-router.com and read the documentation here. If you want to know the new version, if you want to know the version 6, if you want to upgrade version 6, then how will you do it? Because there are changes here. Many changes have been made so far. Earlier, our concept of switch route was going on. Then there was the syntax of routes and route browser router. Then now the syntax of create browser router is going on. So changes keep happening continuously. So you can see which version you want to use. Which version is your project built on? Do you need an upgrade? So for now, the older version is not much older. Older means version 6. I will tell you that too. Along with that, I will also tell you the syntax of our 6th version. I will tell you both the ways so that you will be comfortable. There may be more changes ahead, so you may have to read it. So, you can see it according to yourself. You can read the documentation if you want. It seems a little confusing to read in the starting. That's why I explain it to you properly here. Rest, when you become a pro, you will definitely work with documentation. First of all, let's see how do we work with normal syntax and how do we set up old version. Here you have to keep some things in mind. What is React Router? React Router is a client-side routing library that allows us to create a single-page application. You know how react works, here we don't have to refresh the page, we just replace the part we need to change. Users navigate between pages without refreshing the page. We can navigate between multiple pages. It is a single page, but we are working by creating multiple components in it. One component at a time, if we go to the second route, then the second component at the second time, something like this is happening. Only the necessary components update, improve performance and UX. We will update the components as per the need. And our proper UX will be working. UI UX. Okay. So in React Router DOM, in theory, you don't need to know much. If you do now, you will understand. So React Router version 6 and here the newer version, I will show you the basic setup, how link enabling works, dynamic routing, and programmatic navigation, redirect, nested routing, everything. I will tell you here, it will be fun. First of all, you can see on version 6, if you will see from version 6, the next version, 6.4 or 7, whatever it is, then you will not need to make more changes in it. Logic will be almost the same, it will be working in the same way. It is a little different in syntax, so your work will be done. So here, first of all, let's see the basic setup. Here, the react router version 6, here for basic setup, we use browser router, routes and route. Now, here, understand my point a little carefully first. Thank you. slash home. I just showed you what slash home is. Slash about. slash contact slash help. This way multiple pages, basically multiple routes you have to create. So to create routes, you use routes, routes and route. Basically, you wrap multiple routes inside routes, like about, contact, help. So this way you will create, using routes and route. Now you have created routes and route, Now to send it on that route, you will make a button like anchor tag used to click there but we will not use anchor tag because it is reloading the whole page. So which one will we use? So here react-router-dom provides you link and nav-link. You can use both. You get extra features in nav-link so you can use nav-link. You can also use link if you want normal anchor tag. functionality, there are just a few changes, your work is done, you get some special features in Navlink, which I will tell you now. So to create a route, you can use routes and route, and there to send to that route, to send, to click, we go to that route, for that we use link and navlink. Now these two will work for you only when your application, the whole application will wrap in browser router. Browser router. This is according to the older syntax. According to the new syntax, we use the create browser router syntax. If your application is wrapped in the browser router, whatever component is wrapped in the browser router, in all those components, your link, navlink, routes, route will be working. Otherwise, you will get error. Keep this in mind. What did I say? To create routes and routes, basically to create multiple routes, you have to use routes and routes. To send it there, to go to that route, you have to click and reach there. For that, you have to use link, navlink. And all these things work for you only when you wrap the component in browser router. So you will be able to use all those components which are wrapped in your browser router. If you wrap the app only in browser router, then definitely it will work in all the components. Because we use all the components in the app only. So, wrap the main application in the browser router and your work will be done. So, let's see how we can do this quickly. So, the anchor tag we were using here, now what should we use? Link or nav link. I just told you to send. What do we do to send? Link, nav link. To send. Alright. So, what will we use because of anchor tag? Link. First of all, react-router-dom is your library. I have split the terminal. npm i react-router-dom Simply write this. You can search on the browser and see the installation. Just write this much code. npm i react-router-dom Just write the spelling correctly. You must be able to see the spelling. react-router-dom And if you enter, it will be installed quickly. I have split the terminal and your application is still running. Now I can use the link here. Wait a minute, I didn't get any suggestion. First we will import and then use it. link from react-router-dom. So from here you are getting the link. And keep in mind that the link is named export. So you have to import named here. I mean curly braces in this way and then link and whatever you will get. So you know all this. So here link And what else do you need? Nav link. So first of all, let's see the link. Link is simply attached like this. Link is exactly like anchor tag. When you style anchor tag, then it will be applied to the link. Okay? Yes. Okay. Let's do it. Look at this. So we had applied the hover effect. You must remember. So now see, error has come. Why did error come? Tell me quickly. Why did error come? Look at this. You cannot destruct property based name of react.useContext as it is null. There is some different error, you might not be able to understand. It is an internal error of React Router DOM. But I had just told you that you have to send, you have to make a route, and for both, your component, all your components should be wrapped in BrowserRouter. Did you wrap it? No. How are you using it then? I don't know. You said you have used it. It is not like that. You come here and either wrap this app in BrowserRouter or you want to wrap it in app.jsx. multiple components, then you can do it here too, in this way, import import browser router, see this, it has come here automatically, and here in this way, wrap it in the browser router, so all the components of yours will have to be wrapped inside this browser router, only then you will be able to work in it, otherwise you will not be able to do it, ok, so now bring every component here again and again and work in this way, it is better to wrap the app in main.jsx, then what is the problem, so let's work here, that one, import browser router, ok, and remove the strict mode, there is no need, so instead of strict mode, apply this browser router, there should be no problem, there should be no problem here, so this is done for us to work properly, now we can use routing, ok, so remove the browser router from here, yes, Now if you have installed it in the app, and you are using all the components in the app, then it will work everywhere. Format document. Ok. So let's come here and reload. Wow. See this. Your CSS is also working properly, but you have changed the tag. You have linked it here. Ok. So here it is very similar to anchor tag. So here you don't have to use href, you have to use to. To. Where to go? To. So, 2, 2 and 2. Now, let's come here. Reload it once. Now, I am on help. I clicked on contact. There is no reload, no glitch. Look carefully, I clicked on about. I clicked on about. I clicked on home. I clicked on home. About, contact, help. It looks so smooth. There is no reload or anything. It is working very smoothly. It doesn't look like something is changing. I clicked on help, it reached help, you didn't even know. I clicked on contact, it reached contact, you didn't even know. There is no reload or anything. There will be no complete render, no component will be ordered again. Everything will be fine. As much as change has to be done, only that much change will be done, your work will be done. It has a very good performance. Now we have created this basically, we have done send on the contact page, on the about page, on the help page. Now we will have to make it, we will have to create the route too, then it will be visible too. So let's do it quickly. So how will we create it? First of all, make a component, multiple components. First of all, make home.jsx, R-A-F-C-E. And then after that, make about.jsx. And here, what else can you make? contact.jsx then after that you have one more here, you have help.jsx, make it rafc, ok, help is done, contact is done and about is done and home is done, very good, we have done the work properly in the navbar, so here now what you have to do, What to create? Multiple routes. You have done the work of sending. You have to create multiple routes. What things should be shown on that route? So here you have to use routes first. Which you will definitely get from React Router DOM. And where will it come from? It will come from React Router DOM. So inside routes, you have to create multiple routes. In the routes, you have to create multiple routes. Now to create multiple routes, you use the route here. Okay. And you make route self-closing here like this. No problem should happen. Look. I said you have to create multiple routes. So here I used routes. Now I will make a single route in it. To make a single route, here is route and this is self-closing. I have made it. Okay. Now, what do we give here? We give path. What are we using here in app bar? To. Where to go? So, to slash, where to go? To about, where to go? To contact. Okay? Something like this. And here, we mention path, that what should be seen when it comes. So, like, when it comes to slash, we should see the element of home. We will write element here, and in element, we will give that home component, which we have made. So, import, home, from dot slash component slash home. This is home. Let's import everything first. Home, about, contact and help. Home, about. And here you will get contact. Alright. And here you will get help. Okay. Home is here. This is your about. And this is your contact. And this is your help. Okay. So home, about, contact, help. All the pages have come to you. So, I want when I come on the path of slash, which element should be rendered? Home Okay. In this way, I will create multiple routes. When I come to the path with the slash about, my page should be rendered as about. Okay. When I come to the path with the slash contact, my page should be rendered as contact. Okay. When I come to the path with the slash help, The component that should be rendered should be of help. And for now, I close it like this. Okay. Now, as you can see, we are on help. So you can see the help component. Let's try to make it like a whole page. Wait. Here we give it a class name, page. And let's come to CSS and style it. Although we can use Tailwind, but we will have to write the same CSS in Sub. So it is better that Let's come to app.css and style it below. So,. page. And how should it be in. page? How should it be? Tell me quickly. So, if you give a little black background like this, then you will know how much background it is taking. Will you know? You will know in home. In which we gave it? In about, right? Okay, so where did our CSS go? Here it is. Let's come to about. So, look, this is so small. I want to give it a little more width. So I want its... Sorry, the width is full. I want to give it a height. I give it 60vh. If you give it 90 here, it will actually work. Now I'm not paying much attention to perfect styling. See, this is how much your work is done. The rest is that your navbar is filled up here. Let's bring about in the middle. So what do we have to do for that? For that, here we have display flex. Align item center and justify content center. All right. So this is in the middle of ours and it's looking good. Okay. Okay. So this is looking like a page. So we will come to home. So home is visible. If you come to about, then contact is visible. If you come to help, then help is visible. So now come here and put this class name page in all of them. It is in about. Put it in contact. Put it in help too. If you are keeping it with a little styling, then it will look good to see. There is nothing else. Come to home and come here and come to navbar. Navbar is fine. So home, about, contact and help. It looks proper. Reload it. This error will go to you. So it is working properly. See, there is no reload or anything here. No refresh. Absolutely smooth. Okay. Now I told you that here you have to remove everything from here. It is looking very confusing. I told you that you are putting a link in the navbar, you can also put a navlink. Now let's see what is in navlink. In navlink, you have some special features that they have given. For example, you will use the class name here. Why can't I find the solution of the class name? You will use the class name. So, in class name, you can pass a function in this way. And here you can receive a parameter. You can give any name here and see what is being received here. Like I give any name here. I give A. And here I do CLG A. Okay. Can we do something like this in class name? Yes, we can do it in nav link. So, see what is coming in A. So, we reload. And nav link is not defined. Okay, I think why I am not getting suggestions. So here you have to import the link first. So now it should work properly here. So let's reload. So we have put it on home here. So reload and here you see what you are getting in it. So in this you are getting is active, is pending, is transitioning. So you are getting all these parameters. There is an object, you are getting multiple keys in the object. So here we have the work of is active. What is it doing? See, what is coming now is false. Why? Because we are not at home. As soon as we come to home, then isActive will appear true. Why? Because we have come to home. So, I have to show home as active. In this way, it has to keep orange as orange. If home is active. And if about is active, then about has to keep orange as orange. So, see here, it is false. Because we are not at home. If we go to home, then it is true. So, how will we do the work? So, here we will destructure it. Something like this. And here we will remove the key of isActive. Okay. We will get true and false. So here we will not do much. We will do something like this. Remove these curly braces here. Otherwise, we will have to return. So we don't use curly braces. We keep simple syntax. So here I will write isActive. If it is active, then do something. If it is not, then do something. So if it is active, then I will return here bg. red 500. And if is active, then I won't return anything. Basically, we have to give a class name. Either give your class name, style it with CSS, or give a tailwind class. So I said, if it is active, then keep BG red. So now you come here and see, its background is red. Why? Because it is active already. We are at home. Right? So you get some good features in Naveling. So not BG, actually text So now it looks like this. Then if you come to the contact, then the contact is not active. Why? Because we have only used the link in the contact. If you do this nav link in everything, then you will have fun. Remove this link in some way and do nav link in everything. Here you will come to help. Here you will come to contact. Here you will come to about. And then paste this about here. Copy and paste the contact here. Copy and paste makes it a little easier. So remove it. Now you see, I reload from here. So this contact is active. You don't have to put any separate logic. How will you find out if the contact is active? First take out the params from here, if the contact is active or not, then do that work. There is no need to do all that. Here you are active on help. About is active. So, this navlink is detecting that it is active. It is giving you an isActive key. You can see if it is true or false. If it is true, that means it is active. You can put your class name. That's it. So, the syntax of navlink is very nice. So, you can work in this way. And we also do it in this way. So, you must have understood navlink. You must have understood the link too. Very good. And we don't have to use anchor tag, because it is the same as we used to do in HTML and CSS. So we don't have to do that. Why we don't have to do that? Because we haven't adopted the concept of refresh in react. We have adopted the concept of virtual DOM. We have adopted the concept that the part that needs to be updated should be updated. So we will not ask for the complete data. We will not render the complete data again. We will update only as much as is needed. So, we don't use anchor tag here because it refreshes the page. So, we use react router DOM. So, this is the older syntax. What I have told you in the older syntax. In the older syntax, you have to keep in mind that you have to create a route and you have to send it on the route. The rest of the browser router syntax was in this new version. This will not happen. There will be create browser router. That's it. The logic is almost the same. We have to work on this logic. You understood link-nav-link. The pen tab went back to take oil. Anyway, remove the pen tab. There is no need. We will do it like this. You understood link-nav-link. Dynamic routing. I will tell you this. Then programmatic navigation. I will tell you programmatic navigation first. Then I will tell you dynamic routing. What is programmatic navigation? Programmatic navigation means that For example, I am giving you a nice example. You must have logged in. When you log in, you don't stay on the login page. After logging in, you get redirected. You are made to navigate to the homepage. It happens. Or you must have seen many times that you... Anchor tag and so on. You navigate on button click after performing some logic many times. Like you clicked a button, after clicking a button, some data is fetched and after fetching the data, you have to navigate on some other page after getting the proper response. So how can you do programmatic navigation in a customized way? For that too, you have a solution given by React Rotterdam, which I will tell you. Suppose I don't have to put a link, I have to put a button here. And what do I have to do? Here, Sorry, there is no need to give a class name here. Because our button will already be styled. I say navigate to about. Right? About. Oh man, my about is going a little wrong these days. So this button has come here and the button has come a little wrong. Let's do one thing. Let's do one thing. Not in the navbar, otherwise it will get a little messed up. Right? We have given this as a display flex. Do one thing, take a fragment like this and take this button out of it. Take the button out of this UI we have designed. it looking good? So navigate to home. Let's make it a little smaller. There is a lot of zoom. So when we click on navigate to home, nothing happened. Obviously, you have written some logic. So I say on click. onClick and here we will call a function handleClick and we will make this function here. const handleClick this is our function. Now here any logic can be of yours. On logging in you will put the logic of logging in, you will call the whole API etc. and data basically good response will come. So you will want to navigate. So here you will have some logic and after that logic is complete you want to navigate to the other page. So how will you do it? On the link side, as soon as you click, it gets navigated. You write logic in it or not, it will be navigated. Then logic will work for you. I want us to work here programmatically. If this is the case, then navigate it. If not, then don't navigate it. Like I give one more example here. They can't do login or anything. But a good thing can be done here. Like const is is is logged in is equal to true. So we can put a condition here. If logged in is our is logged in. If we have user logged in, then we have to navigate to the other page. Otherwise, we don't have to. Otherwise, we don't have to. How to work logically? Here, React Router DOM gives you a hook. Which hook? Use Navigate. As soon as the hook comes out of your mouth, you should understand that it will take use. Use Navigate. Use State, Use Effect, Use Navigate. Now, this is not a core hook. If someone asks you, have you used Use Navigate hook? You will say, yes, we have. So, is Use Navigate hook of React? No, it is of React Router DOM. It is not a core hook. It comes with React Router DOM library. you will use the useNavigate hook, the way to use it is very simple, like all the other hooks, you have to use it in the same way, useNavigate and you will call it in this way, save it in a variable, name it const navigate, most of them give the name navigate, if you want, you can give anything here, but giving navigate is fine, it looks a bit standard, so we used the useNavigate hook, here you have a navigate variable, now through this navigate variable, you can navigate anywhere, so navigate, where to navigate, slash, If logged in is true, it will go to about as soon as you click the handle. Let's reload. Navigate to about. Why? Because it is logged in. If I do logged in false, then I will not be able to go to about. So this is how we are working. Programmatic means that we are navigating on the basis of some program. It is not necessary that we have to write some logic. If you want to navigate by clicking on a button or a component, then you can use the hook of useNavigate and navigate on click. So, you have to keep this in mind that useNavigate hook also provides you a react router DOM by which you can use any component, no matter if you have used link or never used link, no matter. You can use useNavigate to navigate on the click of any component. Okay? Okay. You also understand this. After that, you get nested routing, redirect and dynamic routing. First, let's understand dynamic routing. What is dynamic routing? To understand dynamic routing, it will be better through a project, but I will try to explain it to you. You have a multiple product list here. Listen carefully, you will understand why you need to do dynamic routing. Dynamic routing is very easy. It happens a lot. You don't understand why they do it. So, you will understand it now. Then, when you use it in the project, it will become more crystal clear. I said, you will work with API. In the last lecture, we have done everything, API, fetch, XOs, whatever it is. So, You will work with the database, right? You will do fetch etc. So after fetching here, suppose you are fetching the product. Now the pen tab is not working for me, so I am just like this. You will fetch the product. After fetching the product, you will get an array in which there will be 10 products, 20 products, no matter how many products there will be, you will list them all. So in this way, you have a product list. 1, 2, 3, 4, 5. So, all the products that are coming, there will be some limited data, like the name of the product, the title. Now, this does not happen, you have gone to Flipkart, you must have seen that the product list, the smartphone you have searched, then you see multiple smartphones. So, do you see all the data of the smartphone on that page, not of the single smartphone? You click on that smartphone, So, you go to a different page. After going to a different page, you get detailed data related to that smartphone on that page. You see the review and multiple details, description, ratings. A lot of things are seen in detail. Specifications etc. Whereas, you don't see all that data when it is listed. Right? So, we have a similar scenario here. You can see multiple products. You have fetched the data. Now, what you want to do is click on it. Click on it. This product, this product, I want to open its details. How will you open it? So, you have a product slash its ID. Product slash its ID, whatever ID it is. What is its ID? Let's assume it is 1. So, here ID. You send it on this ID URL. So, now using link, using navigate, as you want to send, you send it on this page. Okay. So, you sent it to this page after clicking on it. So, here you have come to the last, slash 1. Listen to me carefully, what came to the last? Slash 1 came. If you had clicked on this, then what should have come in the last? Slash 2 should have come. If you had clicked on this one, then here slash 3. Page is the same. Page is the same. It is a common page for everyone. What is changing? ID is changing. One, sometimes two, sometimes three. Now, if we click on home, then we go to home only. Slash home, slash about. I want to work dynamically. If I click on one product, then its ID will appear here. If I click on this, its ID will appear here. If I click on this, its ID will appear here. If I click on this, its ID will appear here. If I click on this, its ID will appear here. If I click on this, its ID will appear here. Okay? And we don't have to make different pages for each. We have to work on a common page. There will be a common page. It will be a common page. It will be the same logic for everyone. Basically, we have to fetch the data only. We have to fetch all the data related to ID2. Here you can use the fetch API, whatever you want to do. Here you will fetch the URL that you have in this way. How will you fetch? I will tell you using the use params hook. so whatever id you have here, you will give it here, data fetch will happen, so the way to list will be the same for all, whether you list for this, list for this, list for this, so you have to write variables here, you don't have to write exact data, so the same work is happening for everyone, so there is no need to make different components for everyone, different routes to make, did you understand, you may not understand, you may not understand, it will be better clear than the project, ok, so what we have to do here, we have to take this id and work related to that id and same work will be done for all, same component will be used for all, not different like we were making different for home, different route, different component we were rendering, different route for about, different component we were rendering different routes for contact, different components were rendered. It's not like that here. Here, for all the components, if there is some slash 1, then 1 will come, if there is 2, then 2 will come, if there is 3, then 3 will come. Dynamic routing will happen here and the component will be rendered the same. Not different, the same component will be rendered, the same logic will be in all. Okay. So, for that, we use dynamic routing here and it will be clearer for you in the project, but what I will tell you now, it will clear your syntax. So, let's come here. Okay. route, let's make it after contact, contact, slash, now dynamically to get here, what you have to do is, I am saying dollar, you have to put a colon, after putting a colon, whatever you have here, as a key, you can understand it, with this key, you will get ID there, so here you want to write ID, whatever you want to write, you are treating it as a variable. So here, as I write the key, don't write the key, it looks a little weird, I write the CID, contact ID, CID. Okay, this is not that CID, CID, contact ID. Okay, so now what to do here, we have made a route, CID, alright. Now what are we rendering on CID, we are rendering contact, so I will not render contact, I will render something else. So I will render here, Now see carefully, whether it is 1, 2, 3, alpha, beta, gamma, whatever it is, the render will be the same component. whether it is 3, alpha, beta, gamma, whatever it is, render will be the same component. This is what I wanted to tell you. After slash, anything will come here. Like if about is coming, then about is getting rendered. If contact is coming, then contact is getting rendered. If help is coming, then help is getting rendered. But after slash, anything will come here. Your render will be the same. Okay, we have made it dynamic. Really? Yes. Come here. And first of all, do one thing here. Come to detail contact. Here also give it a class name page so that it looks like a page. It is very important to look like a page. I will reload. Okay, here we will have to increase one more link so that you can come directly to it. So wait, after contact, If I type slash 1, then also it is a detailed contact. If I type slash 12, then also you can see a detailed contact. And if I type slash 1 to 3, then also you can see a detailed contact. If I type slash slash alpha, then also you can see a detailed contact page. Right? Now in this detailed contact page, If this is alpha, then we will work with alpha. If this is beta, then we will work with beta. If this is gamma, then we will work with gamma. It means that it is a dynamic route. Whatever comes here, the component has to be rendered the same. We have to work with this key on the same component and work related to it. Okay, let's see how we will do it. Now let's come to this detail contact page. Okay. In the URL, we saw some changes in the last. 1, 2, 3, 4, alpha, beta, gamma. How to take that? For that, here, React Router DOM provides a hook. Its name is use params. Where will it come from? From React Router DOM. Is it a core hook of React? No. Its hook is React Router DOM. You get a library from it, use params. So, we got this hook. Now, the same way to use this hook, use params. And here you have to call like this. Save it in a variable. Give a params name. Whatever name you want to give. I give params only. Do CLG and see what is coming in params. Do CLG and see what is coming in params. Did I write spelling correctly? Params. P-A-R-A-M. Okay. Now you can see what is coming in params by clicking on CLG. If we are on home, then nothing will come because the page of the detailed contact is not rendering. I came to the contact, the contact is rendering. Now after the contact, if I do anything, then you will have the detailed contact rendered. Now look carefully here, you have got an object. What have you got? You have got an object. who has the key is CID. That's why I was telling you to give the key carefully here. The key you are giving, that key is coming to you in that object. If I just make it ID with CID, then what will come to you now, that ID will be coming. C1, C2 will depend on this. Here C1 is there, so C1 is visible. 1, 2, 3, if I do it, then 1, 2, 3 is visible here. Same component is rendering. From there we are just fetching this last one. Because that is dynamic. The same thing is changing again and again, so they are fetching it. Now after fetching it, as I told you, you can call the API here, order data according to it and list it here. So for different products, the same component will render with you and all the details will be visible to you. Okay, I want to show you something like this for now from params.id. All right. So here you have it. You can do something like this. Something like this. Like there is a navbar. So here in navbar, I make an array. arr is equal to a, b, c, d. Suppose for now you have these products. These are the products you have for now. So here, at this place, I Array.map And here you will have one item. And I will return this item in this way. And here you have a nav link. Okay. I'm just telling you to explain. If you don't understand, don't worry. What I just told you is enough. So here you will have one item. One item. Here you will see one item. What is visible. See this. Reload. So, here you can see one item A, B, C, D. So, this is dynamically coming to you from where the data is fetched. Consider it a product, A, B, C, D is a product. So, it is coming dynamically. Now, I want to click on the item that I click on, it will take me to the related page. So, we have to do dynamic routing. So, here we will remove this and use the template literal in this way. Slash and here we will get the item. If I click on A, I will go to A. If I click on B, I will go to B. see here, I click on A, it comes to A, I click on B, it goes to B, so do I have to go here, no, I have to go here, slash, contact, slash, A, B, C, D, dynamic, right, let's load, I clicked on A, contact, slash, A came, so in detailed contact, A is visible, I clicked on B, so it came to B, in detailed contact, B is visible, I clicked on C, it came to C, in detailed contact, C is visible, I clicked on D, it came to D, in detailed contact, D is visible, because we have fetched from params here, So this is how you get multiple products. You have listed the products. After listing, you are going to the related page. And after coming to that page, you are getting its ID. By taking the ID, you can show all the data related to it. It will work in a single component. It is not that if you have a thousand million products, then you have to make a million of card components for it. It is not like that. Not at all. Okay. So, you understood this. So, what did we understand now? Now, we understood what dynamic routing is. You can repeat it a little and see if it is a little confusing. You understood the basic setup. We use link-nav-link to know. We use programmatic navigation, use-navigate-hook for dynamic routing. You have to remember colon while making a route. And you have to remember use-params while taking. What to take? In that route, whatever you have in the last minute, dynamic, A, B, C, D, alpha, delta, whatever is coming, ID is coming, take that. You have to keep that in mind. You have to use use params. Let's understand redirect now. What is redirect, brother? So, redirect is understood by the name that if someone is trying to come to A, redirect him to the home page. Or redirect him to the about page. If someone is trying to come to the login page and he is already logged in, then he cannot come to the login page. Redirect him to the home page. If someone is trying to access the dashboard without login, then as soon as he clicks the dashboard, redirect it to the home page. You are worthy of the home page. There is no login yet. If you want to work in this way, then how will you do it? So for that, you have here a react-router-dom. Again, it provides a navigate. Okay. Import. Use navigate. No, it is not hook. It is a component. Import. Navigate. Okay. See this. It is capital N. Where you can see capital in front, that means it is a component. Right? It is a component. All right. Route is a component. This is a component. All right. The navigate you are going to see is a component. Okay. So, what I want is, for now, I will put it on this help. So, if anyone tries to come to the help page, if someone tries to come to the help page, then I will redirect it on the home page by not showing help. How will we do it? So here we will use the Navigate component. Where did navigate come from? From React Rotter Dom. Okay. So if anyone tries to come to help, then I will use the Navigate component and I will say to. What did I write? To. Where to send it? To slash. To home. Or to about. Whatever you want to send. If someone has come to help, where do you want to send it? You write it here. It will reach there. Really? Yes. I will see here now. I am on contact, on detailed contact, I try to go to help. I will not be able to go to help. I will go to home because it will redirect me. As soon as I clicked on help, I was redirected to home. And a little reload etc. also happened here. So keep this in mind. Okay. Okay, one more concept comes in this. That is replace true. Replace. If you do it, then the old one which you have basically in history, URL is saved and not kept. Means, means, how do I tell you? Means, as you are going to about, browser saves that you went to about. Going to contact, browser saves that you went to contact after about. If you are going to help, then after about, contact, contact, you went to help. So, as you clicked on help, earlier it went to help and redirected to home with help. So, about, contact, help, then home. So, the help one is saved in your history. Did you understand? What did I say? I said that browser saves your history. If you go to about, then this about one is saved. You have route. If you go to contact, then contact one is saved. If you click on help, then first it went to help, then redirected to home. First it went to help, then redirected to home. So, in this way, your history will be saved. about, contact, help, then home. But if you replace true, then after about, contact, and after contact, if you click on help, then help will be deleted from the history. send it directly to home. How will you know? I will not believe in this. I believe in proof, not like this. So I will remove replace and show you. I removed replace and I will do CLG here. What can we use to see the history? Which is coming to my mind right now. Google map window dot history. For now, it is coming to my mind that we can check with window dot history. And some error will come here. We have not given the key anywhere before. Where have we done mapping? In the map bar. Here the key is left to be given. So give the key. Unique key item. So now that error will go. Reload. Now you can see the history here. See the length is 50. You can't see the whole history. But you can see the length here. We have navigated 50 times till now. Let's open a new tab. Ctrl C and paste it here. Now you can see two navigations. By default you have two. Reload. Reload. Two. Go to About. For now, it should be 3. It is 3. Let's go to contact. You should have 4 now. It is 4. Now, if we go to help, it will be 6. Why? Because if we go to help, it will be saved. And if we go to home, it will be saved. So, it will be 6. As soon as I clicked on help, it reached home. Let's reload. It is 6. It is not 5. It is 6. It saved the help file and sent it to home. We want to stop it that the help is going in the middle. Why save the help one? Don't save it. Because if we do it again, it will try to come to help. Now when we do it back here, it will try to come to help first. Back button that you have here in the browser. Now the history is tracking the browser, so you can go back to it with the back button. As soon as you do it back, because it had saved the help route, it will try to go to help. But will it be able to go to help? It will redirect it back to home. So I do it back. I backed it and came back to home. Then I will back. Then I came back to home. So, because it has saved the help one in the middle, so it is a mess. Now I am not able to use the back button properly. On backing, I should have gone to the previous one, but I could not go. So this is a little bit of a mess. So localhost. So now I will show you the second one by doing replace true. Replace. I will do true here. Or just write replace and it will be true. Reload. See, length is 2. I went to about. Length is 3. I went to contact. Length is 4. When I went to help, length was 6 earlier. Now see here. If I redirect to home, then it will not save the help one. Direct will save only the home one. Reload. 5. Length is 5. It is not 6, it is 5. It means it has saved only one. It has not saved the help one in history. It has saved only the home one. So now when I will back, it will not come to help. If it is before help, then it will go to contact. See here. These are small things where your app gets stuck. If you do it, your app gets stuck. So, you have to keep all this in mind. Many times, I myself am stuck in this. Why is this happening? So, I got to know that during redirect, something like this, basically, the have one is also storing in the history. Or whatever is storing in the history during login, you can go back to login. So, this is a bug. You didn't have to go to login. You had to let it go. But you are able to go back to login. Isn't it? So, this is how your work is done. So, you may have understood this. Maybe, there is some confusion left. So, once you will not do it yourself, then you will not understand this. React Router is completely syntax-based. You will have to do it yourself. There is not much logic here. Basically, it is saving in one. If it has not been replaced, then it is saving in history. If it is not being replaced in one, then it is replacing it completely. That's it. It is so simple. There is nothing else here. Huh? Did you understand this much? Where should I go? I should go here. So, you understood the redirect. You understood the programmatic navigation. You understood the dynamic routing. You understood this. You understood this. Let's see the nested routing. How will we do nested routing? For example, in about, I have to do nested routing. That means, about is left. Like, what have we done now? We have this navbar. What is changing? This page is changing. This. A, B, C, D. So, only this page is changing, navbar as it is. So, now I want to do nested. Means, if I am inside about component, then about component should be visible. About component should be visible. And inside that, rest of the nested routing that we have done, should change. Like about 1, about 2, about 3 should come. About as it is should be here. So, how can we do that? About's UI should be as it is. So, how can we do that? So, we have to do nested routing here. So, to do that, It is very easy here. This self-close you have done. Remove self-close. And in this way. Wrap in the route. Whatever route you want to give. Nested routing is done. Yes. Look. Here I have made a route. Self-close. Okay. So first it was about a single route. Now it has become a parent. And inside it. Nested routes are present. So I make one. Here path. Slash about one. Okay. A1. And here we have to make something in element as well. So let's make it. A1. jsx. RFC. You all do it right now. RFC. Okay. And here. A2. jsx. RFC. Okay. A2 is done, A1 is done, here you have A element, A1 will come in the element, not like this, as a component, A1 and according to me, it has not been imported, so import it here, import A1 from dot slash component slash A1, then after that you will come here A2, right? So this is one component in about and another component in about. So now the about page will remain as it is. The routing that we did inside it will change. If you have made something in the about page, it will remain as it is. Now if you go to A1, then this will also appear with the about page and whatever you want to show. But now there is some problem here, I will show you now. A1 is done, A2 is done. So very good. You don't have to put a slash here. Whenever you are doing nested routing, you will not put a slash here. It will be attached to about. So your URL will look something like this. Slash about slash a1. But you don't have to put a slash here. If you don't put a slash, then nested routing is basically linked to it. About slash a1 means about. component and all these things inside it. So for now, you can see about here. Now if you think that about slash A1 should be about, A1 should also be visible, then it will not be visible here. You said that it will be visible here, so why is it not visible here? So we have rendered A1 here. Where has it been rendered? Here, see, single single route is not that if you click on home, then the whole page is removed and home comes. If we click on about, then the whole page will be removed and about will come. Isn't it? It is not like that. Here we have to show about component and also A1. So we have to tell where to show in about. So we have to show it in about. How will we show here? Here you have given two nested routes. You will get that here as an outlet. From where? From react router DOM. Everything will be available from react router DOM. Outlet is a component. What does this outlet do? All the things you have written here, all the things you have written inside this component, all the things you have written inside this component, you get that inside the outlet. If you stick this outlet here, now it's up to you where you want to stick it. If you want to stick it above about, You can use it as a component. If you want to stick above about, then whatever routing you have done here, it will be visible above about. If you want to keep it below, it will be visible below. So in this way, we can tell that the design of about should remain as it is and along with that design, where your nested routes should come. Okay. Assume above was about. Below this also some design would be there. Like, like, like, like. I have made a div here. And give it class name, height, 20. 20 is there. Yes, 20 is there. Width 20. BG and yellow. Give some 700. Right. So this will become some square type. So let's come here. So is it visible in about? Square is not visible. We have given the height and the width. And we have given BG yellow 700. Let's come to home, let's come to about. And let's try to go to the outlet, slash A1. So it's not here yet. Okay, it's visible here. Okay, because the size of its page is so much, we have given the size of the page so much, that's why it's coming down. So this is also a problem here. So remove this class name about. Okay, you will think that we did not give the outlet earlier, then it will also be coming down. So not like that. If you do not give the outlet, then it will not come down. Okay, if you give the outlet, then only you will know where you want to keep it on this page. So you have to tell this. So I want to keep it in the middle. And remove the rest of this class name. So, I want to keep the outlet in the middle of this square. So, if you come to A1, then the A1 page will be rendered. Basically, the A1 component will be rendered, but it will be rendered in the middle of about and square. And if you come to A2, then this A2 is being rendered in the middle of about and square. You want to keep the outlet up, you can keep the outlet up. It came up, you want to keep the outlet down, you can keep the outlet down, it came down. What is the outlet? Nested routes, whatever you have made here. In nested routes, you have to keep in mind that you don't have to put any slash here. This slash about slash a1 automatically links. Did you like it? If you do this once, it will be more fun. What is this? If you do everything, it will be more fun. It is a little syntax wise. That's it. There is nothing else. Logic is very simple in sum. Logic is very simple. Nested route means inside a component, a routing component. A1 will be seen at a time. A2 will be seen at a time. A3 will be seen at a time. So inside this component, All these components. Now where to show this component? So for that you need an outlet. So you put an outlet. This whole component will be rendered at that place. It's amazing. You can design this too. Let's say we made a div. Put this outlet in this div. And give it a class name. Give padding of 10. Or give 20. And give BG red 500. So see this. In outlet this padding came like this. You can see it like this. Okay. A1. A2. This is A1. Okay. If you go somewhere else, you won't find anything. Because it's not dynamic. If you think that B1 and B2 are going to anyone, then it doesn't happen. It doesn't happen that if you click B2 and go to B2, then you won't see anything. This is not about slash B2. Have we made it here? About slash B2. No, it's not like that. Slash about slash A1 is slash about slash A2 is. And what is slash about? So, slash about is. Okay, slash about is. If you want to show something else on slash about, then you can do it like this. Like, don't give anything here. Leave it empty and give something here. So, I believe your A1 will come here like this. Only on about. This one. Okay, so don't do it like this here. I hope you understood this was the older version in the newer version also everything is similar means there is a little syntax change but the logic is completely similar there also you must be having all these things as we have set up here, there will be a little different setup link-nav-link will be exactly the same, dicto will be the same dynamic routing will be done in the same way programmatic navigation will be exactly the same redirect, exact same, nested routing, logic same, syntax a little different. Okay. Dynamic routing, logic same, syntax a little different. In basic setup, syntax a little different. So, let's see that too. Take a break once. What is a break? Yes, a break once. In this video, there will be a break once. Which is going to come now. The school for you will come here. So, take a break once. Then after that, Let's see the new syntax, which is our new version. Here we use the syntax of create browser router. Everything else is the same. Here you get one extra feature. Fetch data before component loads. And there are other new features here that you will have to understand by reading the documentation. This is enough. Okay. Rest, through project, I will be explaining to you that how to use some new features. Isn't it? This is more than enough. You won't get this much on YouTube. Let's discuss the newer version. I'll go drink some water. You also come and drink some water. It'll be fun. Now let's see the syntax of the create browser router. For this, I have set up a new project here. First we were working on Vite, now we are working on Vite 2. Basically, as the previous setup was in Vite, I have done the same setup in Vite 2. And I have installed Tailwind CSS etc. So here are the new syntaxes. Let's see how we will work. The logic is that we have to send on that route and create a route so that we can see the components. We can copy the navbar from here. Copy the navbar from here quickly. Copy the navbar inside the components. And close it here. And make components inside src. And paste it here. So this is our navbar. OK, now here this use Navigate etc. So you do exactly the same thing. Use Navigate the way it was doing. So use Navigate here and see. OK, I'm removing all this. And here. I'm also removing this dynamic routing. This will also do exactly the same thing. I will tell you where the syntax change is. Remove this array. Very good. Remove this button. Okay, okay, okay, use navigate, remove link nav link, very good cropper, we have used link nav link, but there will be an error here as well, how are you using link nav link, did you not get an error, you should have got it, let me see which project we are running here, we are running the V2 one, I believe, so where have we used nav bar, so remove index.css, remove h1 here and use nav bar here, nav bar, It didn't import automatically. No problem, we'll do it. We've put a lot of effort. navbar from dot slash component slash navbar. Alright. So now we'll get the error that how did you use all those things. Okay. So let's reload. And we're getting some error. Fail to resolve react-router-dom. Okay, we haven't installed react-router-dom in this. So split the terminal and quickly install npm i react-router-dom. It will be installed quickly, close it and now you will find some new errors here. See, use location may be used only in the context of a router component. So this is giving a different error, whereas here we have basically the error of the react-router. So you already know what error is here. We have used the bar and we have used the link in the bar. How can we do it? Because here we have not done anything that we are using the browser or not. So here we will not even use the syntax of the browser. We will use a new syntax here and there is no browser in main.jsx. We have not wrapped anything. Remove this strict mode. And remove this too. Okay, main.jsx is neat and clean. Here we are going to work in app.jsx. We will use the syntax of create browser router. So here create browser router and it will be automatically imported from react-router-dom. Can you see? Look, create browser router has come from react-router-dom. Okay, everything will come from react-router-dom now. So, we are going to use create browser router in this way. This is our array of object. What is array of object? That means this is our array and there are one object inside the array. Now, every object is taking path and element from here. Oh, like they used to use route there as a component and they used to give path and element there. Here, you have to keep making object and giving path and element. Is it done? Exactly. This syntax is very easy. Here you have to use array of objects. You don't have to make routes and then give path and element. Here you just have to make one object at a time. This is our one object. This is our second object. In every object you will have a path. Look, I am getting a suggestion. So I gave path as slash. And we will render the component here. Which component will we render? Here element is not component. This is important. Is element also good? Element is also good. Let's see the element or component. I'm a little confused, so I'll have to see here. Create browser router syntax in React. So here I'll see once. Path and element. We have to give path and element. Alright. So path is done. In element, we have to make element here. Component basically have to be made. Ek ho gaya hamare paas home.jsx. Ek ho gaya hamare paas about.jsx. one, we have one, we have one, we have one, we have one, we have one, Very good. So here quickly import. Import home from dot slash component slash home. And after that you will get. Do everything yourself, don't let me do it. About. And contact. This is about you. And this is contact you have. And here we will give in element. About. and then here path slash about sorry not about here we had to give home here we will give element in slash about about about ok after that make another object here give path slash contact and element came to you contact very good See how neat and clean the syntax is. This is done. Browser router is made. Browser router is made. But we haven't told you that we are using it. So we will save it in a variable. Const. And we will give its name. Router. You can give it any name. It is a simple variable. You can give it any name. Okay. Now to use it, you have a router provider. And where will router provider come from? React router will come from DOM. Router provider. Here is router provider. Like this. Now, you have to use the router provider here. This is the router provider. It is self-closing. Very good. Here you have to pass your router in the router prop. This router is the variable. Here you could have written R, RO, ROU. So, you have to pass this ROU here. And this router here. Router is equal to ROU. Whatever you make, you have to give it. So, you provided this router provider. So, will it work now? Not at all. There will still be an error. Because you have made a router provider. It is providing a router. But it has no relation with the navbar if you look carefully. Not at all. It has no relation with the navbar. It means we have not made a wrapping this time. You must be seeing the navbar, the rest must be changing here, they must be doing routing. There is a slight change in the syntax. If you understand the syntax, the rest of the work is the same. So here we don't have to use the navbar in this way. How to do it, I will tell you. See, it is showing about. Why? Because it is on about. If we go to home, then the home will not be visible because we didn't make the home, it was slash. In the slash, it came to home. If we try to go to the slash contact, then it came to contact. So routing is happening. Routing is getting proper. We have told you that you should have home render on last, about render on about, contact render on contact. But now the common component is that navbar should be visible on all. How will it be visible? Navbar should be visible on all components. How will it be visible? So here we will have to do nesting in the first level. Okay, we will have to do nesting. Yes. How we will do it? See this, all these you were giving, this whole component, these three objects, basically three routes, these three routes, you make an object here, give path slash, ok, very good. In element, you will give another element here, and along with that you will give children here, and in children, you will give all these children here. So basically, you are using array of objects in children too. See, understand the syntax a little carefully. I haven't done much. I have nested all these routes a little bit. Path slash is the default. If you have a slash app, then it says slash path. Path slash is the default. What element you have to give here, see that carefully. As we were doing the work of the outlet, we understood that the map bar should come up, whatever it is, it should come here, the rest of the things should be changed. We are going to put the same concept here. So here we don't have to make a component, we have to make a wrapper, so we will name it layout. Most of them work in this way. Although you can also make the app layout.jsx, treat the app as a layout, and do all these things in main.jsx, but I am making it separately. layout.jsx rafce and we will render this layout here. Okay. Layout. Now what will happen with this? What will happen with this? We have rendered the layout, very good, but what will happen with this? What will happen with this is that the navbar we were using here, I will tell you now, you will get an error because you will not have the contact page. You can see the layout in the slash. See, you can see the layout in the slash. Okay, if you go to slash about, then you can see the layout. Slash home was not with us, it was contact. If you go to contact, then you can see the layout. Did you understand anything? You have to catch this much that here is nested routing. With the slash, we have a slash, this is home. Home will be visible here. And a slash should be visible on about. Contact should be visible on contact. At the same time, layout will be visible. As we were nesting there, about will be visible. But A1 will also be visible. A2 will also be visible. In the same way, layout will be visible here. Home can be visible. About can be visible. Contact can be visible. It depends on which route. So how will it look? We haven't shown it here. To show it here, you get the Outlet. Import Outlet. Now you can show the Outlet here. So, wrap it in the fragment like this. And where to show the Outlet? Show it above or below. That's your choice. Now you will see it here. See, you have the layout. Now if you come to the contact, you will see the contact. If you come to the about, you will see the about. Okay, there is no about. There is about. If you come to the about, you will see the about. If you come to the slash, you will see the homepage. So we did nested routing. We made layout as parent. We made layout as parent. And the things that are changing inside it, you will see here. Okay. So now inside this layout, why not add a navbar? So navbar will become common for everyone. Exactly. So the method has changed. The logic has changed a little. Import. Navbar. And here you go up. Here you have the navbar. Ok, it looks like this and here I have not done much in this styling, by going to main.jsx, sorry, by going to index.css, so that's why you are seeing this, if you want, you can do it, isn't it? Your wish, so here it is coming like this and so much for now, let it be, why to focus so much on styling, so see this navbar has come to you. here you have to click on about and if you are coming to about and nav link is installed then the rest of the concepts are exactly the same as in nav link, which is active etc. is the same contact help so we don't have the help page so it will not be visible so if you are coming to about then you can see about if you are coming to home then you can see home and the layout is visible because we have written the layout here remove this so along with the navbar only the outlet will be visible then you have to do more nested routing in this as well so here again make children pass array of objects like this and go to about and take outlet and show it here this syntax will be more easy than the first syntax if you work properly on it this will be more easy because there is no need to make routes separately, simply make an area of object, give path, give path, give element, give element, give children, nest it, go and take the outlet, then if you want to give children in it, give it, go and take the outlet in about, if you want to give children in it, give it, go and take the outlet in contact, show where to show, that's all there is to do, there is nothing else to do, there is only this syntax, okay, So, I hope you understood the syntax. Not like this, we made it separately. And you can do the same thing in main.jsx and you can treat app.jsx as a layout. So, it's up to you how you want to do it. It's a homework for you. You have to do it. You have to create a browser router in main.jsx and you have to use the app here. And you have to do the nesting in it and you have to work with the outlet in the app. You can do this much. Let's see the basic setup. We know the link-nav-link is the same as before. There are no changes. There is no error on the link-nav-link because we have added this router in the router provider. And we have used the layout in the router. So we can use link-nav-link in the components we are using. As we were wrapping here, you can understand that a wrapper has been created here. Whatever components we will use in it, we can use there. Link, nav, link and whatever things are there. Along with that, for dynamic routing, you have to use, sorry, dynamic routing, use params. Basically, by putting a colon, which is coming to you one by one. Look, I will show you. Slash about, slash dollar. You give ID. So here in about page, you have, use params, const params, is equal to use params, you will get from react router DOM, CLG params, now I don't think, it is necessary to do all this, you can do this much, CLG params, same, rest all logic is same, okay, You have to do dynamic routing. Last slash colon. That's it. Come to about. You will not see about now. Because we have made it about slash something. So do one thing. Make it separately. And you have this about page. About page is also done. And We have used about page in both. If you want, you can make it different. But I will show it here. We are using about on about page. And in dynamic routing, we are using about in about slash dollar id. On about page, you will get this empty object. Because here slash something is not coming. Here slash something will be written. Then it will be treated as id. So now you see here. In id, you will get this. Whatever you will write here. So the logic is exactly the same. You have changed the syntax that you had to change. You have changed the basic setup here. Link enabling is the same. Dynamic routing is the same. Programmatic navigation is exactly the same. Use navigate is to be used. Put a button. You can use use navigate by writing logic anywhere. Exactly the same. Redirect is exactly the same. Redirect is also the exact same. If you want to redirect here, if someone comes on Slash Contact, then you have to send it to Home. So, it's the exact same concept. Import, Navigate, and here, remove this, and write here Navigate, and Self-Closing, and 2, where do you want to send? I want to send it on Slash, so I sent it on Slash. Now, if someone wants to come on Contact, then it will go to Home by redirecting. And if you make Replace True, then it will not even save the old URL. Exact same, exact. Then its nested routing, I have just told you. I have done nested routing on the first level. After that, if you want to do it in someone, like in about, then you will make children in about, you will take outlet in about. You will make in home, you will take outlet in about. Okay, so nested routing is also the same, what I have just shown you. Fetch data before component loads. Now you have a new feature that I want to show you. You want to load some data before the data is fetched. Like as soon as I go to home, some data will be loaded before that. Okay, so how can I do it? So to load data for that, you will also need a fake URL here. Come to JSON placeholder. So let's pick up a fake API from here. You have come to use API etc. So let's copy this and I want to do something here before loading. Like I want to load some data before coming to about, then I will put a loader here. I am also getting suggestions, see loader and it is taking a function from you. Now in this function I will simply fetch, simply fetch, simply fetch here. Wait, a little bit of a mess has happened. Fetch and in this way. I have fetched it. Return it carefully. If you don't return, the data will not be returned. There must be something coming after fetching. Now here is one thing that is very interesting. I will tell you that just now. As soon as you go to about, I will reload. As soon as you go to about, there is no data. This console that we have done in about, I will remove the params one. Because you have understood the params one. For params, you can make something separately. So, let's keep it neat and clean. Reload it. So, no data is visible on about. You said that data will be fetched before loading. So, fetch is done here. You have fetched here. So, let's assume that it is being fetched. But how will data be visible on about? For that, again, React Rotterdam provides you a hook which is useLoaderData. Load is done. Now, to use that data, useLoaderData. Which is a hook. You can see use in front. This will give you the data. Really? Yes. const data is equal to useLoadedData and CLG the data. So if you come here carefully and see, we were on home right now. As soon as we come to about, So, we are not getting any data because we have not returned here. See, we have used the syntax of curly braces. So, we have to return. If we don't return, how will it work? If we don't use the syntax of curly braces, then we don't have to return. But now we have to return. So, now let's come to home. See, the data has come. You can see. The data has come. Let's reload. Now we are at home. As soon as we go to about, the data will be phased before coming to about. Interesting. And one more thing you can see carefully, if you have seen the video of Fetch, Fetch Exios, then you should have a confusion here, which is an obvious thing. I told you properly in it that Fetch returns you a promise. For that, you have to await. And after awaiting, the response you get, you have to put that response with dot json and convert it to a normal object. You have to convert it to a readable object. Then you are getting this data. Otherwise, you are not getting this data. So, he released all those problems. You see, you just fetched. No async await, no promise and no need to put all that. Internally, he did all the work. He also did wait for data. He properly converted in data format, readable object format, array of object format. And he gave you proper data. Data only. No response and so on. Data only. Now you can use Fetch or Axios. For Axios, you have to install the library. So if you are using Fetch here, then your work will be done easily. Okay. So as soon as you were at home, nothing will come. If you come to about, then it will fetch the data. And if you want to take data on about, then to take data, use loader data. And you get the data. And you can list the data here. That's it. Shall I show you by listing the data? What is coming in the data? So a lot of things are coming. I just list the name. I will just list the name of the company here data.map each object is coming to you, item syntax is a little bit wrong, this is a higher order function so here you will have item and here it is necessary to return and here in h1 item.name And we are getting this error because we have not wrapped it in a fragment. We can't return multiple components. You know all these things. So look here, you can see all the names and it is coming in a very big size. I have used H1, so use paragraph. So it will be small. So it is in home, so no data is coming. As soon as it comes to about, the data will be loaded. That's great. That's great. Use the item here. Did you enjoy it? Did you enjoy it? All the possible things that we mostly use and we can say more than enough. I have told you all the things. You will have to practice. Because there is a lot of syntax in it. Logic wise it is very simple. But there is a lot of syntax. So syntax wise you will have to keep in mind that where to put colon, dynamic routing happens. what to keep in mind while doing programmatic navigation, when to replace in redirect, when not to replace, how to take outlet in nested routing, link, navlink, what is the difference between link and navlink, navlink has many special features, one of which I have told you, syntax of both is different, which we have seen in older version and new version, so I have told you a lot in this, So if you have done it yourself, it would have been fun. Otherwise, you would have been bored. It looks a little strange to see syntax, syntax, syntax. How is it like this? So when you don't do it, you won't know until you do it yourself. Oh, that's all I had to do here. If you do it yourself, it will be fun. Okay, so our react router DOM is also ours. Sorry. Yes, I am saying right. Our React Router DOM is also completed. The project was going to come, but I did not bring it in the project because I thought I will tell you the concept of routing. Then we can do a good project. Right? And this is done. We will try to do a good project. Then we will go to state management. And then after that, all the projects we have saved, which I have basically given in the roadmap, then we will do that project. Alright, then we will meet in the next lecture. Till then, keep exploring and bye-bye.