Full React Tutorial #21 - The React Router

Поделиться
HTML-код
  • Опубликовано: 27 окт 2024

Комментарии • 210

  • @danujajayasuriya9438
    @danujajayasuriya9438 2 года назад +315

    it should be noted that starting from react-router-dom v6, has been replaced by .

    • @davidbryanramboy5043
      @davidbryanramboy5043 2 года назад +6

      Is that only new changes that tackle from the video?

    • @chasec4897
      @chasec4897 2 года назад +30

      ​@@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 2 года назад +4

      @@chasec4897 singleton only

    • @chasec4897
      @chasec4897 2 года назад +1

      @@davidbryanramboy5043 discovered that a few moments later

    • @melissacouturier5644
      @melissacouturier5644 Год назад

      Thank you! was wondering!!

  • @jeremy2217
    @jeremy2217 2 года назад +227

    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 года назад +3

      ​@@dobrealexandru1776 Don't do that. Make that html into a component and

    • @vidblogger12
      @vidblogger12 2 года назад +19

      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

  • @i_am_human_being5570
    @i_am_human_being5570 3 года назад +32

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

  • @effiemmanuel1927
    @effiemmanuel1927 2 года назад +13

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

  • @neilcartwright6369
    @neilcartwright6369 3 года назад +125

    If there's a better course on React I'd love to see it. Clear, concise, thoroughly brilliant.

    • @hank91918
      @hank91918 3 года назад +19

      it doesn't exist, this is as good as it gets!

    • @ejay
      @ejay 3 года назад +1

      Dev Ed's is pretty great

    • @samart3010
      @samart3010 3 года назад +3

      Codevolution reactjs playlist is also brilliant

    • @dlegand4951
      @dlegand4951 3 года назад

      scrimba react boot camp

  • @sertacekici3342
    @sertacekici3342 3 года назад +36

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

  • @druludwig
    @druludwig 3 года назад +12

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

  • @azeezismaila846
    @azeezismaila846 2 года назад +12

    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 года назад +5

      Glad you're enjoying it! :)

  • @heavydirtysoul1491
    @heavydirtysoul1491 3 года назад +8

    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.

  • @darexleon
    @darexleon 2 года назад +13

    Nice! For v6 I used this code:

  • @gabrielenguidanos7690
    @gabrielenguidanos7690 10 месяцев назад +1

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

    • @NetNinja
      @NetNinja  10 месяцев назад

      Thanks Gabriel! :)

  • @sueholder703
    @sueholder703 3 года назад +7

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

  • @PrashantAmoli
    @PrashantAmoli 3 года назад +8

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

  • @michaelcapone8913
    @michaelcapone8913 Год назад +2

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

  • @martiananomaly
    @martiananomaly 2 года назад +14

    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

  • @whatnowZA
    @whatnowZA 2 года назад +2

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

  • @raphaelfreitas4565
    @raphaelfreitas4565 2 года назад +2

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

    • @NetNinja
      @NetNinja  2 года назад +1

      Thanks, hope it was helpful!

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

  • @MannkumarPandya
    @MannkumarPandya 4 месяца назад

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

  • @legendaryknight6462
    @legendaryknight6462 3 года назад +1

    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 года назад +2

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

  • @dannyman2200
    @dannyman2200 3 года назад +5

    Loving this playlist, clearing up so many things

  • @andredesantana2188
    @andredesantana2188 3 года назад +4

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

  • @Ivan-Shyriaiev
    @Ivan-Shyriaiev Год назад +3

    Solution if you have problem such as [Home] is not an element or
    import {BrowserRouter as Router, Route, Routes} from 'react-router-dom';

  • @nipunamunasinghe
    @nipunamunasinghe 2 года назад

    Thank you so much! I explored a lot websites to learn how to use routes. Finally I found this video. Thank you so much!

  • @musaabdalwahed5645
    @musaabdalwahed5645 3 года назад +7

    Thank you ninja for this great effort.

  • @yyyooohhhooo
    @yyyooohhhooo 3 года назад +1

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

  • @lollilolli4582
    @lollilolli4582 2 года назад

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

  • @uhyahaa8371
    @uhyahaa8371 3 года назад

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

  • @randomthings1300
    @randomthings1300 Год назад +2

    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

  • @jayanspaliwal5907
    @jayanspaliwal5907 2 года назад +2

    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

  • @danialranjbar9805
    @danialranjbar9805 2 года назад

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

  • @ayushman_sinhaa
    @ayushman_sinhaa 2 года назад

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

  • @Sohanjs
    @Sohanjs 9 месяцев назад +1

    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 8 месяцев назад

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

  • @sanjaycosmos9547
    @sanjaycosmos9547 Год назад

    Thanks man for clear explanation 🙌

  • @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 года назад +1

      Haha, good spot. I think my accent confuses them enough, gotta throw some native pronunciations in there occasionally :)

  • @CodeRCreatives
    @CodeRCreatives 3 года назад +3

    Thank you for this awesome react series.

  • @sameerpokharel3531
    @sameerpokharel3531 3 года назад

    thank you Net ninja You're the Best Teacher

  • @ameyapatil1139
    @ameyapatil1139 3 года назад

    Wow this one was so so clear !! Excellent job

  • @IndunilUdayalal
    @IndunilUdayalal 3 года назад +1

    This is a great video. Thank you very much.

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

  • @balakiswe
    @balakiswe 3 года назад

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

  • @Cdswjp
    @Cdswjp 2 года назад +1

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

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

  • @halitsalihoglu4536
    @halitsalihoglu4536 2 года назад

    Now I understand React thanks man :)

  • @rabitebibi
    @rabitebibi 3 года назад

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

  • @ramakrishnarudraraju6948
    @ramakrishnarudraraju6948 3 года назад

    Great Video. Straight to the point.

  • @viniciusm.m.7822
    @viniciusm.m.7822 2 года назад +1

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

  • @MaybeKian
    @MaybeKian 3 года назад

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

  • @danalex2991
    @danalex2991 2 года назад

    Brilliant Explanation

  • @ScrilloTube
    @ScrilloTube 2 года назад +1

    thanks you very much from algeria

    • @NetNinja
      @NetNinja  2 года назад +2

      You are welcome! Hi to Algeria :)

  • @akhrorbekabdukhamitov8872
    @akhrorbekabdukhamitov8872 2 года назад +9

    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?

  • @engahd746
    @engahd746 3 года назад +3

    U can use too

    • @ridl27
      @ridl27 3 года назад

      preffered way for me.

    • @arturdeandrade7443
      @arturdeandrade7443 3 года назад +1

      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 года назад +1

      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 года назад +1

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

  • @omarshoura6327
    @omarshoura6327 2 года назад

    amazing job. Simple and to the point

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

  • @trantrungnghia9642
    @trantrungnghia9642 8 месяцев назад

    if you don’t double check to see if you have liked this guy’s videos or not, you are a criminal

  • @md.ashrafulalam7533
    @md.ashrafulalam7533 3 года назад +1

    please also make another tutorial using react and firebase

  • @HieuNguyen-cg1kd
    @HieuNguyen-cg1kd 9 часов назад

    If you use react-router-dom v6, this is a correct code
    import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
    import Navbar from './Navbar';
    import Home from './Home';
    function App() {
    return (










    );
    }
    export default App;

  • @vladimirputindreadlockrast812
    @vladimirputindreadlockrast812 Год назад +1

    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.

  • @user-sg4ek2dd3h
    @user-sg4ek2dd3h 2 года назад

    Thank you! Helped a lot 👍

  • @Arjun8BPCracker
    @Arjun8BPCracker 3 года назад

    Daymnnn that's the easiest explanation to this!

  • @cruickshankatc
    @cruickshankatc 8 месяцев назад

    Great video! Thank you!

    • @NetNinja
      @NetNinja  8 месяцев назад

      Thanks for watching! :)

  • @younesbav0up316
    @younesbav0up316 2 года назад

    well explained thank you sir

  • @jamesmuriuki3785
    @jamesmuriuki3785 3 года назад

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

  • @nandopookey9195
    @nandopookey9195 2 года назад

    Thankyou very much sir

  • @basilm.b8499
    @basilm.b8499 10 месяцев назад +1

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










    );
    }

  • @candle-likeghost9523
    @candle-likeghost9523 3 года назад +7

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

    • @ArnoldsKtm
      @ArnoldsKtm 3 года назад +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

  • @afrikanking4022
    @afrikanking4022 3 года назад

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

  • @tarekghosn3648
    @tarekghosn3648 2 года назад

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

  • @henterpeter4806
    @henterpeter4806 3 года назад +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 3 года назад

      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.

  • @masaocodes
    @masaocodes 2 года назад

    Nice tutorial!

  • @andromilk2634
    @andromilk2634 7 месяцев назад

    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?

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

  • @reinhardheydrich314
    @reinhardheydrich314 3 года назад

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

  • @xdotli
    @xdotli 3 года назад

    Jesus it is so well explained.

  • @dannyman2200
    @dannyman2200 3 года назад +1

    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 ?

  • @architdutt
    @architdutt 3 года назад

    Simply amazing

  • @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 года назад +3

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

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

  • @nischalmohan2409
    @nischalmohan2409 3 года назад

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

  • @donbigosso
    @donbigosso 3 года назад

    So f**king clear! Thanks!

  • @neo90sr
    @neo90sr 3 года назад +1

    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 3 года назад +3

      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 3 года назад

      @@neo90sr Thanks

  • @Manozkirati
    @Manozkirati 3 года назад

    Was waiting... thanks..

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

  • @drhastings
    @drhastings 3 года назад

    i keep wondering why people dislike tutorials, Why ??

  • @GiancarloCarccamo
    @GiancarloCarccamo 2 года назад

    great video

  • @subee128
    @subee128 Год назад

    Thanks

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

  • @andrewneilclarke
    @andrewneilclarke 3 года назад

    Great tutorial!! Thanks so much. But, as a fellow Englishman, how are you pronouncing route/router!?!?!! 😂

  • @piekeheijmans7472
    @piekeheijmans7472 3 года назад

    allright then gang

  • @leiwang8891
    @leiwang8891 2 года назад

    Thanks!

    • @NetNinja
      @NetNinja  2 года назад

      Thanks for your support Lei Wang! much appreciated :)

  • @perschonca
    @perschonca 2 года назад

    If i finish all of these videos, will i be a net ninja?

    • @NetNinja
      @NetNinja  2 года назад +1

      Yes. Officially 😃

    • @perschonca
      @perschonca 2 года назад

      @@NetNinja Hell yeah, I'm going to need to buy a shirt if it's official.
      Thank you for your hard work

  • @Martin-p8z8m
    @Martin-p8z8m 8 месяцев назад

    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

  • @yakaproduction_official2203
    @yakaproduction_official2203 Месяц назад

    Try this if you faced an error
    import Navbar from './Navbar';
    import Home from './Home';
    import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
    function App() {
    return (










    );
    }
    export default App;

  • @eanonuevo
    @eanonuevo 3 года назад

    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

  • @theobellash6440
    @theobellash6440 2 года назад

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

  • @moathdw910
    @moathdw910 3 года назад

    What is the best way to handle routes with auth?

  • @cybulix
    @cybulix 2 года назад

    Can we get video about version 6?

  • @PatrickPereiraVieira04
    @PatrickPereiraVieira04 2 года назад +1

    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?