No video

Full React Tutorial #21 - The React Router

  Рет қаралды 506,996

Net Ninja

Net Ninja

Күн бұрын

In this React tutorial we'll talk about the React Router & see how to set it up so that we can have multiple 'pages' on our React websites.
🐱‍💻 🐱‍💻 Course Files:
+ github.com/iam...
🐱‍👤🐱‍👤 JOIN THE GANG -
/ @netninja
🐱‍💻 🐱‍💻 My Udemy Courses:
+ Modern JavaScript - www.thenetninj...
+ Vue JS & Firebase - www.thenetninj...
+ D3.js & Firebase - www.thenetninj...
🐱‍💻 🐱‍💻 Helpful Links:
+ HTML & CSS Course - • HTML & CSS Crash Cours...
+ Modern JavaScript course - • Modern JavaScript Tuto...
+ Get VS Code - code.visualstu...
🐱‍💻 🐱‍💻 Social Links:
Facebook - / thenetninjauk
Twitter - / thenetninjauk
Instagram - / thenetninja

Пікірлер: 206
@danujajayasuriya9438
@danujajayasuriya9438 2 жыл бұрын
it should be noted that starting from react-router-dom v6, has been replaced by .
@davidbryanramboy5043
@davidbryanramboy5043 Жыл бұрын
Is that only new changes that tackle from the video?
@chasec4897
@chasec4897 Жыл бұрын
​@@davidbryanramboy5043 I had an error that a private route couldn't be used in short term, the solution was to make the links as the below: }>
@davidbryanramboy5043
@davidbryanramboy5043 Жыл бұрын
@@chasec4897 singleton only
@chasec4897
@chasec4897 Жыл бұрын
@@davidbryanramboy5043 discovered that a few moments later
@melissacouturier5644
@melissacouturier5644 Жыл бұрын
Thank you! was wondering!!
@jeremy2217
@jeremy2217 2 жыл бұрын
Good work as usual ! For V6 of react-router-dom use instead of and place your componant inside an element attribute import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
@dobrealexandru1776
@dobrealexandru1776 2 жыл бұрын
Hi , i want to place html in Route , how can i do that?
@nikhildhakal3727
@nikhildhakal3727 2 жыл бұрын
​@@dobrealexandru1776 Don't do that. Make that html into a component and
@vidblogger12
@vidblogger12 2 жыл бұрын
Gotta love front end development, where even a tutorial from 1 year ago is already outdated, and 3 new JS frameworks were released in the time it takes you to watch that tutorial! :D
@alucard8678
@alucard8678 2 жыл бұрын
was just about to comment this
@oho6786
@oho6786 2 жыл бұрын
ty
@neilcartwright6369
@neilcartwright6369 3 жыл бұрын
If there's a better course on React I'd love to see it. Clear, concise, thoroughly brilliant.
@hank91918
@hank91918 3 жыл бұрын
it doesn't exist, this is as good as it gets!
@ejay
@ejay 2 жыл бұрын
Dev Ed's is pretty great
@samart3010
@samart3010 2 жыл бұрын
Codevolution reactjs playlist is also brilliant
@dlegand4951
@dlegand4951 2 жыл бұрын
scrimba react boot camp
@darexleon
@darexleon 2 жыл бұрын
Nice! For v6 I used this code:
@mohitgangwani6054
@mohitgangwani6054 Жыл бұрын
it worked.thanks
@i_am_human_being5570
@i_am_human_being5570 3 жыл бұрын
This person makes learning so easy. Specially because the tutorials are of short length.
@effiemmanuel1927
@effiemmanuel1927 2 жыл бұрын
This is the best React Crach Course on KZbin ngl! For react-router-dom V6 you can use something like this:
@martiananomaly
@martiananomaly Жыл бұрын
For people who want to use react-router-dom v6.X, Make the import statement: import { BrowserRouter as Router, Route, Routes} from 'react-router-dom'; and make the JSX:
@OdessaSenpai
@OdessaSenpai Жыл бұрын
Thank you for this hope he pins this
@ayisiree
@ayisiree Жыл бұрын
@@OdessaSenpai Thanks for this. I had a blank screen for 20 minutes
@Ancient244
@Ancient244 Жыл бұрын
instead of router use BrowserRouter
@gabrielenguidanos7690
@gabrielenguidanos7690 8 ай бұрын
You're the godfather of tutorials. Concise, clear, perfect
@NetNinja
@NetNinja 8 ай бұрын
Thanks Gabriel! :)
@sertacekici3342
@sertacekici3342 3 жыл бұрын
When I need to learn something about react you add a video about it. Thank you so much
@sueholder703
@sueholder703 3 жыл бұрын
8:00 explains how a React application is delivered to a client compared to a non-react website. So nice to get that understanding.
@druludwig
@druludwig 3 жыл бұрын
Thank you for so often explaining the "why" behind what you're doing
@azeezismaila846
@azeezismaila846 2 жыл бұрын
Thank you so much, I only just started react 2 days ago and you have given a wide grasp of it. You make it so fun
@NetNinja
@NetNinja 2 жыл бұрын
Glad you're enjoying it! :)
@heavydirtysoul1491
@heavydirtysoul1491 3 жыл бұрын
When I need to learn any new technology about web development I go straight to this channel and check for a tutorial. Most of the times I learn it from here firstly. It is a great channel.
@michaelcapone8913
@michaelcapone8913 Жыл бұрын
Wow ! The first 3 minutes when you explained how react works is just amazing.
@PrashantAmoli
@PrashantAmoli 3 жыл бұрын
Hey Ninja, great tutorial and explanation🙏. I feel like you are the tutor I was searching for all this time on KZbin. Your way of teaching is effective for me and the tutorials are just what I have planned to learn. Keep up the good work👍 and keep updating old tutorials like you you did here with functional programming in React. Super excited to learn a lot from you💯.
@whatnowZA
@whatnowZA 2 жыл бұрын
Sticking with version 5 was smart because version 6 removed Switch for Routes. Thanks for the turorial.
@raphaelfreitas4565
@raphaelfreitas4565 2 жыл бұрын
A big thank you from Brazil 🇧🇷 !!! Great explanation and demonstration...
@NetNinja
@NetNinja 2 жыл бұрын
Thanks, hope it was helpful!
@martinrombach2666
@martinrombach2666 2 жыл бұрын
You're the best introduction I've had on React, out of 4. Good job man, you really know how to teach :)
@jayanspaliwal5907
@jayanspaliwal5907 Жыл бұрын
Update for react router 6: use instead of what's in the video @The Net Ninja kindly pin this comment so that people don't search through the entire comment section for answer. Thank you
@randomthings1300
@randomthings1300 Жыл бұрын
Those who are using react-router-dom v6, please note some syntax change in the routing part- Switch has been removed and Routes have been introduced in place of that. refer below snippet please
@baro1620
@baro1620 Жыл бұрын
what if i want to add into first route for example and ?
@randomthings1300
@randomthings1300 Жыл бұрын
@@baro1620 Then you can add another route for Auth path say path="/user/auth" and element as e.g.
@randomthings1300
@randomthings1300 Жыл бұрын
@@baro1620 However if you want to force user to Login page all the time when they are not logged in to application and once they login they should be able to create Then you have to have a mechanism to detect is user Authenticated and then allow to access to application accordingly This will ensure user is forced to login page if not logged in
@labmember0045
@labmember0045 Жыл бұрын
Thanks buddy appreciate it
@dannyman2200
@dannyman2200 3 жыл бұрын
Loving this playlist, clearing up so many things
@andredesantana2188
@andredesantana2188 3 жыл бұрын
Shaun you are a LEGEND!!! THANK YOU SO MUCH FOR THE AMAZING TUTORIAL!!!!!!
@Sohanjs
@Sohanjs 7 ай бұрын
For react-router-dom v6 onwards: import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; Switch has been replaced by Routes and the Routes component requires that its children be either a or a . In version 6, the element prop is used instead of nesting components directly. The element prop takes the JSX element to render for the specified route.
@_itshenry
@_itshenry 7 ай бұрын
Do i need to save pages as .JSX or i could still use .JS
@legendaryknight6462
@legendaryknight6462 3 жыл бұрын
Shaun , u are so amazing . I love the way u explain everything . There is no body on earth who can do like what u do . I can not explain my feelings really . for about 2 years what ever I watched from your channel was the best of the best and how intelligently u plan to explain and make step by step guides in a very understandable way is so wonderful. I will be for ever member of this channel and will tell everybody u are my Hero. This channel worth 1 billion subscribers. Thank you Shaun ❤🐱‍👤❤.
@tomaszswiatek4612
@tomaszswiatek4612 3 жыл бұрын
You may need to restart react by write in terminal "npm start" to proper run react-router:). Thx Shaun again for next lessons:)
@soulju9144
@soulju9144 Жыл бұрын
We've been studying react for the past couple weeks with a test in a couple days. Definitely thought I was going to fail but you've given me hope! Lol. Thank you
@yyyooohhhooo
@yyyooohhhooo 3 жыл бұрын
Man.. this is clearer than crystal. thank you!
@musaabdalwahed5645
@musaabdalwahed5645 3 жыл бұрын
Thank you ninja for this great effort.
@user-ih5qg6xc7n
@user-ih5qg6xc7n 3 ай бұрын
Thanks Net Ninja for this content also thank to this community who posted how to achieve same in V6.. Thanks
@nipunamunasinghe
@nipunamunasinghe Жыл бұрын
Thank you so much! I explored a lot websites to learn how to use routes. Finally I found this video. Thank you so much!
@alanproduction910
@alanproduction910 Жыл бұрын
why doesn't work for me?
@lollilolli4582
@lollilolli4582 2 жыл бұрын
Listening your course is not boring for you have such a pleasant voice , thank you xaxa :)
@akhrorbekabdukhamitov8872
@akhrorbekabdukhamitov8872 2 жыл бұрын
for those who are using react-router-dom V6 your code should look like this
@dobrealexandru1776
@dobrealexandru1776 2 жыл бұрын
What about placing html functions like or , how can i put that in Route?
@danialranjbar9805
@danialranjbar9805 2 жыл бұрын
Thank u for ur efforts for building all these great tutorials. Thank u
@uhyahaa8371
@uhyahaa8371 3 жыл бұрын
Oh boii.... the best tutorials on yt. thanks mate
@trantrungnghia9642
@trantrungnghia9642 7 ай бұрын
if you don’t double check to see if you have liked this guy’s videos or not, you are a criminal
@Ivan-Shyriaiev
@Ivan-Shyriaiev Жыл бұрын
Solution if you have problem such as [Home] is not an element or import {BrowserRouter as Router, Route, Routes} from 'react-router-dom';
@yashprog1359
@yashprog1359 Жыл бұрын
Thank you! 😊
@IndunilUdayalal
@IndunilUdayalal 3 жыл бұрын
This is a great video. Thank you very much.
@engahd746
@engahd746 3 жыл бұрын
U can use too
@ridl27
@ridl27 3 жыл бұрын
preffered way for me.
@arturdeandrade7443
@arturdeandrade7443 3 жыл бұрын
It does simplify things, but if you plan to pass any props to the component , it seems to be easier when it's nested. I'm still learning though, so I might be wrong about this.
@fjohanssondev
@fjohanssondev 3 жыл бұрын
The preferred way is to use the children method (as shown in the video). One thing to notice is that by using component={Whatever}, it will trigger React to create a new component for each render. Instead of updating the existing one. Also, I think the "to" prop is mostly used within links (Link, NavLink and such). While "path" is mostly considered to be used within the . I don't know if there's any difference using "to" within , does the "exact" prop work in that way?
@ridl27
@ridl27 3 жыл бұрын
@@fjohanssondev nah, its also "path", not a "to" attribute. He did a typo. And now I need to make research about component={Whatever}. Never thought that it could trigger React to create a new component for each render..
@therichardchannel
@therichardchannel 3 жыл бұрын
@@arturdeandrade7443 How do you pass props if it's written in this non-nested way?
@mehrabmehmood7874
@mehrabmehmood7874 2 жыл бұрын
Thank you for this Great Series. So much simplified and very well explained.
@NetNinja
@NetNinja 2 жыл бұрын
Glad it was helpful! Thanks Mehrab :)
@ayushman_sinhaa
@ayushman_sinhaa 2 жыл бұрын
Thank you so much for this video ! It really helped me get a clear understanding of React Router
@sameerpokharel3531
@sameerpokharel3531 3 жыл бұрын
thank you Net ninja You're the Best Teacher
@rabitebibi
@rabitebibi 3 жыл бұрын
Always at the top. Updated, and explained so ..... thx.
@balakiswe
@balakiswe 3 жыл бұрын
This is some excellent skills to explain in that simple way.... cheers...
@Cdswjp
@Cdswjp 2 жыл бұрын
Thanks. It would be awesome if you created a video that shows how to use more than 1 bundle.js file in a project.
@ameyapatil1139
@ameyapatil1139 3 жыл бұрын
Wow this one was so so clear !! Excellent job
@CodeRCreatives
@CodeRCreatives 3 жыл бұрын
Thank you for this awesome react series.
@basilm.b8499
@basilm.b8499 8 ай бұрын
In recent versions of react-router-dom, the Switch component has been replaced by Routes function App() { return ( ); }
@nihatbastan5561
@nihatbastan5561 8 ай бұрын
Thank you man!!
@sanjaycosmos9547
@sanjaycosmos9547 10 ай бұрын
Thanks man for clear explanation 🙌
@NetNinja
@NetNinja 10 ай бұрын
No problem 👍
@digitalpartner7598
@digitalpartner7598 2 жыл бұрын
please mate you are the best , your method is the best , i learned a lot from you, would you please add a full MERN stack tutorials, it would be gentle , thanks
@viniciusm.m.7822
@viniciusm.m.7822 2 жыл бұрын
This video is beautiful! Obrigado, brother! Deus abençoe!
@omarshoura6327
@omarshoura6327 2 жыл бұрын
amazing job. Simple and to the point
@halitsalihoglu4536
@halitsalihoglu4536 2 жыл бұрын
Now I understand React thanks man :)
@ScrilloTube
@ScrilloTube 2 жыл бұрын
thanks you very much from algeria
@NetNinja
@NetNinja 2 жыл бұрын
You are welcome! Hi to Algeria :)
@MaybeKian
@MaybeKian 2 жыл бұрын
great tutorial man, typescript + react would be really helpful too!
@ramakrishnarudraraju6948
@ramakrishnarudraraju6948 2 жыл бұрын
Great Video. Straight to the point.
@Arjun8BPCracker
@Arjun8BPCracker 3 жыл бұрын
Daymnnn that's the easiest explanation to this!
@candle-likeghost9523
@candle-likeghost9523 3 жыл бұрын
aliasing when destructuring When import: { Aaa as Garbage } When assign variable : { Aaa : Garbage } WHy?
@ArnoldsKtm
@ArnoldsKtm 3 жыл бұрын
because object assignment operator is ":" import deconstructors are not objects per see and "as" is an alias operator long story short - deal with it
@KevinMullarkey
@KevinMullarkey 2 жыл бұрын
Brilliant tutorial Shaun, very clear voice and you explain everything clearly and easily.....but 'rowt' instead of 'root' for an Englishman!? I assume is for the American audience ;)
@NetNinja
@NetNinja 2 жыл бұрын
Haha, good spot. I think my accent confuses them enough, gotta throw some native pronunciations in there occasionally :)
@cruickshankatc
@cruickshankatc 6 ай бұрын
Great video! Thank you!
@NetNinja
@NetNinja 6 ай бұрын
Thanks for watching! :)
@md.ashrafulalam7533
@md.ashrafulalam7533 3 жыл бұрын
please also make another tutorial using react and firebase
@user-sg4ek2dd3h
@user-sg4ek2dd3h 2 жыл бұрын
Thank you! Helped a lot 👍
@henterpeter4806
@henterpeter4806 3 жыл бұрын
Hi @theNetNinja. Does the way React handles routing mean that at the initial request the server returns all the possible content to the browser, and then React sorts out locally what to show to the user? In case of complex websites this can be quite a lot of data, couldn't it? What can be done, so that users don't have to wait for too long before the landing page gets rendered?
@codymccarty9327
@codymccarty9327 2 жыл бұрын
I was wondering this same thing! It can't be the case, bc netflix uses react and they don't send every show they have everytime I open the app.
@danalex2991
@danalex2991 2 жыл бұрын
Brilliant Explanation
@tarekghosn3648
@tarekghosn3648 2 жыл бұрын
i feel every message should be written differently but over all thank you
@klirmio21
@klirmio21 Жыл бұрын
I just love you bro Why do people pay for courses? If there's such brilliant free tutorials by godsent people like you? thank you! love frm Ukraine
@neo90sr
@neo90sr 2 жыл бұрын
I have an error with switch. Attempted import error: 'Switch' is not exported from 'react-router-dom'. Does anyone know how to solve this? Looks like switch is not used anymore
@neo90sr
@neo90sr 2 жыл бұрын
I found the solution on stackoverflow. In the new react version, "switch" is replaced by "routes" and the component you want to render is inserted inside the "route" as a prop. Also "exact" is not required anymore.
@VTechBroLive
@VTechBroLive 2 жыл бұрын
@@neo90sr Thanks
@andromilk2634
@andromilk2634 6 ай бұрын
Could you have called your home route instead of "/", for example, "/home"? Is this just a convention to begin your initial page only with a forward slash?
@STUPIDYOUTUBE_HIDINGMSGS
@STUPIDYOUTUBE_HIDINGMSGS 3 жыл бұрын
So this ROUTE component, how will that affect and clash with the NODE.js routing if you're doing a MERN application? Which one wins, react router or Node router?
@afrikanking4022
@afrikanking4022 2 жыл бұрын
New Sub here... I love how you teach found you today
@vladimirputindreadlockrast812
@vladimirputindreadlockrast812 Жыл бұрын
As a beginner, React errors are frustratingly not well documented, IMO. My React app blew up after I ran the react-router-dom as described in this video. After a couple days of research, then giving up, then coming back to this video, I think I managed to fix it: 1) Uninstall Node.js on my Windows 11 machine. 2) Reboot 3) Fresh install Node.js 20.2.0 4) react create-app dojo-blog 5) enter dojo-blog folder 6) npm run start 7) npm install react-router-dom@5 8) npm json-server --watch data/db.json --port 8000 ...and my app is working without errors. As you can see, I did things a little out of order, swapping steps 7 & 8. I think the real fix here may have been the newest Node version, 20.n.
@dannyman2200
@dannyman2200 3 жыл бұрын
Obviously Node does a lot more, BUT in terms of handling requests does this router aspect of React negate Node and Express making them unnecessary for React apps ?
@younesbav0up316
@younesbav0up316 2 жыл бұрын
well explained thank you sir
@nischalmohan2409
@nischalmohan2409 3 жыл бұрын
A question about BrowserRouter as Router. What is the difference between that and Say " { data: blogs,.. } ?
@xdotli
@xdotli 3 жыл бұрын
Jesus it is so well explained.
@jamesmuriuki3785
@jamesmuriuki3785 3 жыл бұрын
Thanks Ninja, coming back to React and this has made it so simple to level up!!!
@jelouche
@jelouche 2 жыл бұрын
Small update with react-router-dom, Switch is not longer the keyword to place routes inside your application. Instead use Routes.
@ericmomoh7927
@ericmomoh7927 2 жыл бұрын
Watch the video from the beginning he stated something. That is because the time of doing the tutorial router version 6 was in beta mode so he chooses to use version 5 router which was stable then. Always watch video thoroughly before making comments. Cheers mate.
@jelouche
@jelouche 2 жыл бұрын
@@ericmomoh7927 @Eric Momoh bruhh, i think you should read the comments carefully yourself first. I said update as in there is a new update. I myself was figuring out the new syntax for couple of minutes. So I commented so it might help someone as it is one of the most popular tutorial video on react. Cheers 🥂
@nandopookey9195
@nandopookey9195 2 жыл бұрын
Thankyou very much sir
@subee128
@subee128 Жыл бұрын
Thanks
@m4cdemos
@m4cdemos Жыл бұрын
Many thanks for all your hard work - as a Brit, I can even (just about!) forgive you for pronouncing it 'rowt' instead of 'root'.... We already have to spell 'color' incorrectly, surely there's no need to speak 'US English' as well 🙄🙂
@architdutt
@architdutt 3 жыл бұрын
Simply amazing
@maximk7816
@maximk7816 3 жыл бұрын
May I ask you some thing? If I show/hide components by routing does it make the same effect as mounting/unmounting components? I mean, in terms of rerendering?
@bennyxfoo
@bennyxfoo 2 жыл бұрын
Thank you for the excellent tutorial. I am trying to convert my website to a react website. I use the traditional tags to route between pages and within pages. I am trying to use but it doesn't seem to work with "#id" eg. in the same page or on another page. It works ok with and . I am not sure what I am missing. Should I just stick with tags instead of . Would appreciate some help.
@reinhardheydrich314
@reinhardheydrich314 3 жыл бұрын
thank u , this help me a lots love u :D
@masaocodes
@masaocodes 2 жыл бұрын
Nice tutorial!
@theobellash6440
@theobellash6440 2 жыл бұрын
How do you lazy load component when a route is first activated ?
@GiancarloCarccamo
@GiancarloCarccamo 2 жыл бұрын
great video
@eanonuevo
@eanonuevo 2 жыл бұрын
I got 'Error: Failed to compile'. I need to import 'import React from 'react' in every JavaScript files that uses JSX. For it to compile successfully
@user-nj1jj3xw2z
@user-nj1jj3xw2z 6 ай бұрын
super, danke
@dobrealexandru1776
@dobrealexandru1776 2 жыл бұрын
How do i use html in Route ? i can t just put in there cus it says that [p] is not a component
@donbigosso
@donbigosso 2 жыл бұрын
So f**king clear! Thanks!
@stephenmuchara6696
@stephenmuchara6696 11 ай бұрын
just in case someone revisits here router V6
@drhastings
@drhastings 3 жыл бұрын
i keep wondering why people dislike tutorials, Why ??
@piekeheijmans7472
@piekeheijmans7472 3 жыл бұрын
allright then gang
@andrewneilclarke
@andrewneilclarke 3 жыл бұрын
Great tutorial!! Thanks so much. But, as a fellow Englishman, how are you pronouncing route/router!?!?!! 😂
@Manozkirati
@Manozkirati 3 жыл бұрын
Was waiting... thanks..
@InvincibleMan99
@InvincibleMan99 2 жыл бұрын
How do you re direct from a function based on sone condition ?
@mishkathossain2984
@mishkathossain2984 11 ай бұрын
What can I do now?? the current running version of react dom is 18. I googled it?? how do I install it?? can anyone help me???
@moathdw910
@moathdw910 3 жыл бұрын
What is the best way to handle routes with auth?
@1qazxsw2010
@1qazxsw2010 2 жыл бұрын
Switch is deprecated in version 6. You use Routes.
@ericmomoh7927
@ericmomoh7927 2 жыл бұрын
At the time of making the tutorial version 6 was in beta mode newly released, so he chooses to use version 5 router which was a stable version then. He stated it clearly at the router Installations.
@marcinmaj3609
@marcinmaj3609 3 жыл бұрын
Refresh react redux too with hooks
Full React Tutorial #22 - Exact Match Routes
5:24
Net Ninja
Рет қаралды 243 М.
React Router - Complete Tutorial
23:53
Cosden Solutions
Рет қаралды 111 М.
Unveiling my winning secret to defeating Maxim!😎| Free Fire Official
00:14
Garena Free Fire Global
Рет қаралды 16 МЛН
This Dumbbell Is Impossible To Lift!
01:00
Stokes Twins
Рет қаралды 42 МЛН
Dad gives best memory keeper
01:00
Justin Flom
Рет қаралды 20 МЛН
КТО ЛЮБИТ ГРИБЫ?? #shorts
00:24
Паша Осадчий
Рет қаралды 4,3 МЛН
Learn React With This One Project
42:38
Web Dev Simplified
Рет қаралды 769 М.
Full React Tutorial #27 - Controlled Inputs (forms)
9:27
Net Ninja
Рет қаралды 301 М.
Full React Tutorial #20 - Making a Custom Hook
8:49
Net Ninja
Рет қаралды 263 М.
Learn React Router v6 In 45 Minutes
46:20
Web Dev Simplified
Рет қаралды 554 М.
All useEffect Mistakes Every Junior React Developer Makes
22:23
Full React Tutorial #17 - Fetching Data with useEffect
7:55
Net Ninja
Рет қаралды 345 М.
Unveiling my winning secret to defeating Maxim!😎| Free Fire Official
00:14
Garena Free Fire Global
Рет қаралды 16 МЛН