Full React Tutorial #21 - The React Router

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/iamshaunjp/Complet...
🐱‍👤🐱‍👤 JOIN THE GANG -
/ @netninja
🐱‍💻 🐱‍💻 My Udemy Courses:
+ Modern JavaScript - www.thenetninja.co.uk/udemy/m...
+ Vue JS & Firebase - www.thenetninja.co.uk/udemy/v...
+ D3.js & Firebase - www.thenetninja.co.uk/udemy/d...
🐱‍💻 🐱‍💻 Helpful Links:
+ HTML & CSS Course - • HTML & CSS Crash Cours...
+ Modern JavaScript course - • Modern JavaScript Tuto...
+ Get VS Code - code.visualstudio.com/
🐱‍💻 🐱‍💻 Social Links:
Facebook - / thenetninjauk
Twitter - / thenetninjauk
Instagram - / thenetninja

Пікірлер: 207

  • @danujajayasuriya9438
    @danujajayasuriya9438 Жыл бұрын

    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
    @jeremy22172 жыл бұрын

    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

    Жыл бұрын

    ty

  • @neilcartwright6369
    @neilcartwright63693 жыл бұрын

    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

  • @i_am_human_being5570
    @i_am_human_being55702 жыл бұрын

    This person makes learning so easy. Specially because the tutorials are of short length.

  • @effiemmanuel1927
    @effiemmanuel19272 жыл бұрын

    This is the best React Crach Course on KZread ngl! For react-router-dom V6 you can use something like this:

  • @darexleon
    @darexleon2 жыл бұрын

    Nice! For v6 I used this code:

  • @mohitgangwani6054

    @mohitgangwani6054

    Жыл бұрын

    it worked.thanks

  • @druludwig
    @druludwig2 жыл бұрын

    Thank you for so often explaining the "why" behind what you're doing

  • @PrashantAmoli
    @PrashantAmoli3 жыл бұрын

    Hey Ninja, great tutorial and explanation🙏. I feel like you are the tutor I was searching for all this time on KZread. 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💯.

  • @sertacekici3342
    @sertacekici33423 жыл бұрын

    When I need to learn something about react you add a video about it. Thank you so much

  • @sueholder703
    @sueholder7033 жыл бұрын

    8:00 explains how a React application is delivered to a client compared to a non-react website. So nice to get that understanding.

  • @martinrombach2666
    @martinrombach26662 жыл бұрын

    You're the best introduction I've had on React, out of 4. Good job man, you really know how to teach :)

  • @azeezismaila846
    @azeezismaila8462 жыл бұрын

    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
    @heavydirtysoul14913 жыл бұрын

    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.

  • @dannyman2200
    @dannyman22003 жыл бұрын

    Loving this playlist, clearing up so many things

  • @michaelcapone8913
    @michaelcapone8913 Жыл бұрын

    Wow ! The first 3 minutes when you explained how react works is just amazing.

  • @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

  • @legendaryknight6462
    @legendaryknight64622 жыл бұрын

    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 ❤🐱‍👤❤.

  • @gabrielenguidanos7690
    @gabrielenguidanos76907 ай бұрын

    You're the godfather of tutorials. Concise, clear, perfect

  • @NetNinja

    @NetNinja

    7 ай бұрын

    Thanks Gabriel! :)

  • @andredesantana2188
    @andredesantana21883 жыл бұрын

    Shaun you are a LEGEND!!! THANK YOU SO MUCH FOR THE AMAZING TUTORIAL!!!!!!

  • @yyyooohhhooo
    @yyyooohhhooo3 жыл бұрын

    Man.. this is clearer than crystal. thank you!

  • @musaabdalwahed5645
    @musaabdalwahed56453 жыл бұрын

    Thank you ninja for this great effort.

  • @tomaszswiatek4612
    @tomaszswiatek46123 жыл бұрын

    You may need to restart react by write in terminal "npm start" to proper run react-router:). Thx Shaun again for next lessons:)

  • @ayushman_sinhaa
    @ayushman_sinhaa2 жыл бұрын

    Thank you so much for this video ! It really helped me get a clear understanding of React Router

  • @CodeRCreatives
    @CodeRCreatives3 жыл бұрын

    Thank you for this awesome react series.

  • @balakiswe
    @balakiswe3 жыл бұрын

    This is some excellent skills to explain in that simple way.... cheers...

  • @rabitebibi
    @rabitebibi3 жыл бұрын

    Always at the top. Updated, and explained so ..... thx.

  • @lollilolli4582
    @lollilolli45822 жыл бұрын

    Listening your course is not boring for you have such a pleasant voice , thank you xaxa :)

  • @ameyapatil1139
    @ameyapatil11393 жыл бұрын

    Wow this one was so so clear !! Excellent job

  • @danialranjbar9805
    @danialranjbar98052 жыл бұрын

    Thank u for ur efforts for building all these great tutorials. Thank u

  • @omarshoura6327
    @omarshoura63272 жыл бұрын

    amazing job. Simple and to the point

  • @raphaelfreitas4565
    @raphaelfreitas45652 жыл бұрын

    A big thank you from Brazil 🇧🇷 !!! Great explanation and demonstration...

  • @NetNinja

    @NetNinja

    2 жыл бұрын

    Thanks, hope it was helpful!

  • @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?

  • @whatnowZA
    @whatnowZA2 жыл бұрын

    Sticking with version 5 was smart because version 6 removed Switch for Routes. Thanks for the turorial.

  • @maximk7816
    @maximk78163 жыл бұрын

    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?

  • @uhyahaa8371
    @uhyahaa83713 жыл бұрын

    Oh boii.... the best tutorials on yt. thanks mate

  • @MaybeKian
    @MaybeKian2 жыл бұрын

    great tutorial man, typescript + react would be really helpful too!

  • @mehrabmehmood7874
    @mehrabmehmood78742 жыл бұрын

    Thank you for this Great Series. So much simplified and very well explained.

  • @NetNinja

    @NetNinja

    2 жыл бұрын

    Glad it was helpful! Thanks Mehrab :)

  • @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

    10 ай бұрын

    instead of router use BrowserRouter

  • @user-ih5qg6xc7n
    @user-ih5qg6xc7nАй бұрын

    Thanks Net Ninja for this content also thank to this community who posted how to achieve same in V6.. Thanks

  • @IndunilUdayalal
    @IndunilUdayalal3 жыл бұрын

    This is a great video. Thank you very much.

  • @ramakrishnarudraraju6948
    @ramakrishnarudraraju69482 жыл бұрын

    Great Video. Straight to the point.

  • @Sohanjs
    @Sohanjs6 ай бұрын

    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

    5 ай бұрын

    Do i need to save pages as .JSX or i could still use .JS

  • @viniciusm.m.7822
    @viniciusm.m.78222 жыл бұрын

    This video is beautiful! Obrigado, brother! Deus abençoe!

  • @bennyxfoo
    @bennyxfoo2 жыл бұрын

    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.

  • @henterpeter4806
    @henterpeter48063 жыл бұрын

    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.

  • @sameerpokharel3531
    @sameerpokharel35313 жыл бұрын

    thank you Net ninja You're the Best Teacher

  • @user-sg4ek2dd3h
    @user-sg4ek2dd3h2 жыл бұрын

    Thank you! Helped a lot 👍

  • @dannyman2200
    @dannyman22003 жыл бұрын

    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 ?

  • @halitsalihoglu4536
    @halitsalihoglu45362 жыл бұрын

    Now I understand React thanks man :)

  • @reinhardheydrich314
    @reinhardheydrich3143 жыл бұрын

    thank u , this help me a lots love u :D

  • @dobrealexandru1776
    @dobrealexandru17762 жыл бұрын

    How do i use html in Route ? i can t just put in there cus it says that [p] is not a component

  • @sanjaycosmos9547
    @sanjaycosmos95479 ай бұрын

    Thanks man for clear explanation 🙌

  • @NetNinja

    @NetNinja

    9 ай бұрын

    No problem 👍

  • @Cdswjp
    @Cdswjp2 жыл бұрын

    Thanks. It would be awesome if you created a video that shows how to use more than 1 bundle.js file in a project.

  • @digitalpartner7598
    @digitalpartner75982 жыл бұрын

    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

  • @younesbav0up316
    @younesbav0up3162 жыл бұрын

    well explained thank you sir

  • @afrikanking4022
    @afrikanking40222 жыл бұрын

    New Sub here... I love how you teach found you today

  • @danalex2991
    @danalex29912 жыл бұрын

    Brilliant Explanation

  • @eanonuevo
    @eanonuevo2 жыл бұрын

    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

  • @nischalmohan2409
    @nischalmohan24093 жыл бұрын

    A question about BrowserRouter as Router. What is the difference between that and Say " { data: blogs,.. } ?

  • @Manozkirati
    @Manozkirati3 жыл бұрын

    Was waiting... thanks..

  • @cruickshankatc
    @cruickshankatc5 ай бұрын

    Great video! Thank you!

  • @NetNinja

    @NetNinja

    5 ай бұрын

    Thanks for watching! :)

  • @jamesmuriuki3785
    @jamesmuriuki37853 жыл бұрын

    Thanks Ninja, coming back to React and this has made it so simple to level up!!!

  • @xdotli
    @xdotli3 жыл бұрын

    Jesus it is so well explained.

  • @durgaprasadvinukonda
    @durgaprasadvinukonda Жыл бұрын

    Hi All, All of sudden when I started installing router package in my machine . My npm not working . Throwing me proxy behind error. Although I have deleted proxy details but still facing issue . Can someone help me to fix this issue ?

  • @STUPIDYOUTUBE_HIDINGMSGS
    @STUPIDYOUTUBE_HIDINGMSGS2 жыл бұрын

    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?

  • @vikrant260
    @vikrant2602 жыл бұрын

    I am having an error for 'BlogList' Component and i.e. React must be in the scope when using jsx...can anybody tell me why is the happening & how to resolve it..please

  • @nandopookey9195
    @nandopookey91952 жыл бұрын

    Thankyou very much sir

  • @masaocodes
    @masaocodes2 жыл бұрын

    Nice tutorial!

  • @architdutt
    @architdutt3 жыл бұрын

    Simply amazing

  • @Arjun8BPCracker
    @Arjun8BPCracker3 жыл бұрын

    Daymnnn that's the easiest explanation to this!

  • @theobellash6440
    @theobellash64402 жыл бұрын

    How do you lazy load component when a route is first activated ?

  • @moathdw910
    @moathdw9103 жыл бұрын

    What is the best way to handle routes with auth?

  • @CleverCpp
    @CleverCpp2 жыл бұрын

    thanks you very much from algeria

  • @NetNinja

    @NetNinja

    2 жыл бұрын

    You are welcome! Hi to Algeria :)

  • @andromilk2634
    @andromilk26345 ай бұрын

    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?

  • @mishkathossain2984
    @mishkathossain298410 ай бұрын

    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???

  • @donbigosso
    @donbigosso2 жыл бұрын

    So f**king clear! Thanks!

  • @InvincibleMan99
    @InvincibleMan992 жыл бұрын

    How do you re direct from a function based on sone condition ?

  • @surbhigoyal5595
    @surbhigoyal55953 жыл бұрын

    how to can add routers in separate file and call that file in my application??

  • @neo90sr
    @neo90sr2 жыл бұрын

    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

  • @KevinMullarkey
    @KevinMullarkey2 жыл бұрын

    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 :)

  • @Zangief001
    @Zangief001 Жыл бұрын

    Thank you so much!

  • @NetNinja

    @NetNinja

    Жыл бұрын

    You're welcome Jam! :) hope it was helpful

  • @md.ashrafulalam7533
    @md.ashrafulalam75333 жыл бұрын

    please also make another tutorial using react and firebase

  • @GiancarloCarccamo
    @GiancarloCarccamo2 жыл бұрын

    great video

  • @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

  • @candle-likeghost9523
    @candle-likeghost95233 жыл бұрын

    aliasing when destructuring When import: { Aaa as Garbage } When assign variable : { Aaa : Garbage } WHy?

  • @ArnoldsKtm

    @ArnoldsKtm

    2 жыл бұрын

    because object assignment operator is ":" import deconstructors are not objects per see and "as" is an alias operator long story short - deal with it

  • @engahd746
    @engahd7463 жыл бұрын

    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?

  • @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

  • @user-nj1jj3xw2z
    @user-nj1jj3xw2z5 ай бұрын

    super, danke

  • @subee128
    @subee128 Жыл бұрын

    Thanks

  • @nishokrr118
    @nishokrr118 Жыл бұрын

    can you guys tell me whats the font he is using?

  • @adelgafo7412
    @adelgafo74123 жыл бұрын

    that's amazing

  • @piekeheijmans7472
    @piekeheijmans74722 жыл бұрын

    allright then gang

  • @leiwang8891
    @leiwang8891 Жыл бұрын

    Thanks!

  • @NetNinja

    @NetNinja

    Жыл бұрын

    Thanks for your support Lei Wang! much appreciated :)

  • @ridl27
    @ridl273 жыл бұрын

    ty

  • @nurhusni
    @nurhusni3 жыл бұрын

    5:07 I just realized. Why does the class App start with capital but the class contents doesn't?

  • @swanarmaan

    @swanarmaan

    3 жыл бұрын

    That doesn't matter. This is just for styling with CSS and you can name it either way.

  • @basilm.b8499
    @basilm.b84997 ай бұрын

    In recent versions of react-router-dom, the Switch component has been replaced by Routes function App() { return ( ); }

  • @nihatbastan5561

    @nihatbastan5561

    6 ай бұрын

    Thank you man!!

  • @Mahmudulhasan-ts5hm
    @Mahmudulhasan-ts5hm3 жыл бұрын

    thanks

  • @PatrickPereiraVieira04
    @PatrickPereiraVieira042 жыл бұрын

    I got 6 high severity vulnerabilities after installing T_T I tried doing it with version 5 first and then installed version 6. Still got the same vulnerabilities. Even by using npm audit fix and npm audit fix --force, it's the same. Anyone got a fix or shall i just continue with the tutorial?

  • @-UPH-KRISHNAM

    @-UPH-KRISHNAM

    2 жыл бұрын

    same

  • @user-dw1ve1qk2n

    @user-dw1ve1qk2n

    Жыл бұрын

    did u find a solution for it?

  • @marcinmaj3609
    @marcinmaj36093 жыл бұрын

    Refresh react redux too with hooks

  • @tarekghosn3648
    @tarekghosn36482 жыл бұрын

    i feel every message should be written differently but over all thank you