React Router 6.4 - Getting Started

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024
  • Get started with React Router 6.4, learn how it differs from 6.x and how you can use its amazing new data-fetching (and submission) features!
    Learn all about React.js with my full course: acad.link/reactjs
    Join our Academind Community on Discord: academind.com/...
    Check out all our other courses: academind.com/...
    Code: github.com/aca...
    (check out different branches for starting code etc.)
    ----------
    • Go to www.academind.com and subscribe to our newsletter to stay updated and to get exclusive content & discounts
    • Follow @maxedapps and @academind_real on Twitter
    • Follow @academind_real on Instagram: / academind_real
    • Join our Facebook community on / academindchannel
    See you in the videos!
    ----------
    Academind is your source for online education in the areas of web development, frontend web development, backend web development, programming, coding and data science! No matter if you are looking for a tutorial, a course, a crash course, an introduction, an online tutorial or any related video, we try our best to offer you the content you are looking for. Our topics include Angular, React, Vue, Html, CSS, JavaScript, TypeScript, Redux, Nuxt.js, RxJs, Bootstrap, Laravel, Node.js, Progressive Web Apps (PWA), Ionic, React Native, Regular Expressions (RegEx), Stencil, Power BI, Amazon Web Services (AWS), Firebase or other topics, make sure to have a look at this channel or at academind.com to find the learning resource of your choice!

ความคิดเห็น • 113

  • @xo.vlarios
    @xo.vlarios วันที่ผ่านมา

    Oh my goodness, you are the best!!!!!! I am trying to teach myself this for a class, and other tutorials were not cutting it. I got discouraged when I saw that you’re teaching this top-down, which I usually don’t like as too much code confuses me. But holy, you took your time and explained every detail very meticulously!

  • @abdullahbelkaid1684
    @abdullahbelkaid1684 2 ปีที่แล้ว +11

    I was looking for this tutorial because i got lost with the documentation especially they made it using vite , thank you so much

  • @SrimalPriyanga
    @SrimalPriyanga 2 ปีที่แล้ว +7

    Really impressive tutorial, Obvious on to the point without annoying sounds and talks. Thank you! Love It! Subscribed!

    • @dylansharp8041
      @dylansharp8041 2 ปีที่แล้ว +1

      This comes from his Javscript course on Udemy which is massive and, imo, really really good.

  • @ChrisBrown-si1vg
    @ChrisBrown-si1vg 14 วันที่ผ่านมา

    Thanks for the video! Much easier to follow than just doing doc diving on the router dom website.

  • @transfer1992
    @transfer1992 ปีที่แล้ว

    Thank you!
    I find myself going back to this video whenever I forget anything about RR's new features. Great video!

  • @pyrocentury
    @pyrocentury ปีที่แล้ว +15

    How would one leverage the new data features in v6.4+ when integrating with state management like Redux or HTTP client like Axios? Seem like there is a lot of refactoring to do if we want to bring these features in to an existing project. A lot of these libraries require accessing the history outside the react context. I would appreciate a video covering refactoring a project like that to see how you would tackle some of the challenges.

    • @somerandomchannel382
      @somerandomchannel382 ปีที่แล้ว +2

      the first thing a library should do is address all loopholes and common usages in their new way. If not, it is not a

    • @denisotim7640
      @denisotim7640 ปีที่แล้ว

      Yeap - I was also wondering about this 😐

  • @dimitaruzunov54
    @dimitaruzunov54 ปีที่แล้ว

    The video is as always perfect!!! The problem that bothers me is where is "Separation of concerns" gone? The router needs just to "route"/render the required page, but not messing with data loading (task for service layer) and error handling (again another taks). How such app is going to be scallable and testable...

  • @SahilRajput03
    @SahilRajput03 2 ปีที่แล้ว +2

    Amazing video, Its so lovely to see all this from you.
    I would can not read docs of this coz I really wanted to see it from people like you..
    Love you man!

  • @patrickjreid
    @patrickjreid ปีที่แล้ว +1

    Max this is so helpful. a version with redux toolkit would be incredible. I know Remix makes redux largely unnecessary but I am dealing with an ecommerce site that has a usecase for it. Also using it with things like react-query would be a cool tutorial too. Thanks for all your great content!

  • @ktoscos4546
    @ktoscos4546 9 หลายเดือนก่อน

    Very helpful video , I am wonderin if component need wait for fetch data before render , would it make effect of page suspension?

  • @orlandocastaneda3169
    @orlandocastaneda3169 ปีที่แล้ว +1

    this is super useful, i was a bit stuck with the documentation and this tutorial helped me a lot to understand some things

    • @eazy2195
      @eazy2195 ปีที่แล้ว

      That must have been the worst documentation I've ever read, it starts you off with installing some unnecessary libraries just so you can code along, it doesn't explain half the things, starts of with the most confusing examples, nightmare.. They should just pin this video instead as an official doc guide

  • @skoodath
    @skoodath 2 ปีที่แล้ว +1

    Thanks for the tutorial. I was kind of getting lost somewhere between v6.3 and v6.4. This one helped!

  • @mertylmaz6288
    @mertylmaz6288 2 ปีที่แล้ว +12

    Hey Max. Thanks for the video. You really made me understand react 2 years ago. What do you think about react-query? I use it a lot and it's less complex and easier to use than the features of 6.4

    • @alejandrovillarroel7855
      @alejandrovillarroel7855 2 ปีที่แล้ว +3

      I also use react query for everything, no more context or redux, its just easier with react (tanstack) query

    • @Aldabil
      @Aldabil 2 ปีที่แล้ว +6

      @@alejandrovillarroel7855 Redux/Context still has it use case that does not clash with react-query, they have total different objective so they actually don't "substitute" each other. Nonetheless, Redux has introduced RTK-query which actually can be compared/substituted with react-query.

  • @jamesdenmark1396
    @jamesdenmark1396 ปีที่แล้ว +1

    It's great tutorial, and straight to the point! The only missing thing he didn't mention in this video is how to get the types from the deferred loader! I think react-router. didn't create type utils for that?

    • @Abken.
      @Abken. 7 หลายเดือนก่อน +2

      10 months late response... But you can use react-router-typesafe for type inference based on the loader.
      Example:
      // loaders
      export const itemsLoader = (() => defer({ dataAsync: fetchItems() })) satisfies LoaderFunction; // using npm i react-router-typesafe for type inferrence for the useLoaderData, error hooks and RRv6 Await component in React 18 Suspense, etc.
      // then just use it in the browser router like loader: itemsLoader
      export const Items = () => {
      const { dataAsync: itemsLoaderAsync } = useLoaderData(); // Note: it will be strongly typed based on the loader automatically
      return (


      {/* Note: items will be strongly typed automatically to the type coming from the query in the loader, e.g. Array */}
      {(items) => items.map((item) => {item.description})}


      );
      };
      Important note: if the loader is async, it will still block the component from mounting and it will not be properly deferred. Always return the whole promise in the defer, so it can be properly awaited with React Router 6 Await inside a React 18 Suspense

  • @krtrvi
    @krtrvi ปีที่แล้ว

    Thanks Amazing tutorial, very much helped to update the react router 5 to 6 without any issues :)

  • @theuniverse685
    @theuniverse685 2 ปีที่แล้ว +5

    Really cool! I'm wondering how complicated it could be if you started using React Router 6.4 and then wanted to move to NextJS

    • @DavidSmith-ef4eh
      @DavidSmith-ef4eh 2 ปีที่แล้ว

      Was thinking the same. The features seem cool, but would make it harder to add htem to nextjs. Right now the pages in our cra app (spa style) can be easily importet in the nextjs SSG app, and they just work, since the component knows how to fetch the data itself. Wouldn't really work with this approach though, or you'd have to create a wrapper component and pass in the loader and teh PageComponent, and handle the data fetching there... Too much work if you ask me 🤣

  • @shotgun600
    @shotgun600 ปีที่แล้ว

    Thank you for the react 6.4 new features guide. It's very helpful.

  • @deepakbhatt7494
    @deepakbhatt7494 ปีที่แล้ว

    Awesome one I have one question how we can use with latest react-router-dom.

  • @omarkarim9298
    @omarkarim9298 2 ปีที่แล้ว +9

    Angular has had this since v2 with guards

    • @mkru37
      @mkru37 ปีที่แล้ว

      Angular had this since version 1 - using angular-ui-router. ;)

  • @ed-jamal
    @ed-jamal 2 ปีที่แล้ว +1

    Thank you for this video
    Could you tak a look at tankstack/table
    Update from v7 to v8

  • @ktoscos4546
    @ktoscos4546 9 หลายเดือนก่อน

    Very great tutorial , i have learnt a lot. Certainly I will check others materials :)

  • @AfonsoFilipeJr
    @AfonsoFilipeJr ปีที่แล้ว

    This video is perfect, thanks!!
    qq, why do we need to specify the main navigation in the error page if the error is also nested in the outlet?

  • @gentlecoder5167
    @gentlecoder5167 2 ปีที่แล้ว +9

    It's obvious they make all these fancy features just for the sake of Remix. I don't need all of that in my React app. In more or less serious project no one handles data fetching manually, we have react-query, apollo, rtk-query etc for such things.

  • @EmiliaKaida
    @EmiliaKaida ปีที่แล้ว +1

    Has the API & functionalities changed much from v 6.0 to the latest (6.8) ?
    Are there any breaking changes?
    I want to know because I learned about the features of v6 from a course that taught in v 6.0 beta, not sure if there'll be entirely new things now.

  • @dluca182
    @dluca182 ปีที่แล้ว +1

    man, the video was amazing!
    The official doc...meh.. i'm a total beginner so I didn't have any previous knowledge or base, and most of questions and online tutorials have almost nothing about this version, so, while learning the first things about react router, I have to learn how was it before and try to convert it on the fly.
    Plus I started using fetching to a backend with JWT and is all going sideways having to use tokens and not being able to use Hooks inside loaders or actions...i'm so lost
    Watching your video gave me a bit of hope, i'll have to change some routes I did because I think I mixed up some structure between different versions.
    Hope to find somethign useful with the defer and await functions

  • @rafiqulislamtusher8605
    @rafiqulislamtusher8605 2 ปีที่แล้ว +1

    Thanks for this video. What is your opinion if I use any react library to handle Form data, error, etc instead of the new Form feature of react-router-6.4

    • @user-vm3vf8sq1z
      @user-vm3vf8sq1z 2 ปีที่แล้ว

      Helpline📲📥⬆️
      Questions can come in⬆️

  • @jeffkinley3698
    @jeffkinley3698 ปีที่แล้ว

    Thanks! Great tutorial. Do you happen to have a demo app somewhere with this running?

  • @thesunabsolute
    @thesunabsolute 2 ปีที่แล้ว +38

    Maybe I'm in the minority here, but I am not a fan of the router taking over all of this additional functionality. I get that they are trying to unify React Router with their Remix Run framework, but IMO a router should just be a router. There are other libraries like SWF and React Query that already make data fetching easy and trivial. I can already see this making the testing story more complex, by now having to mock the data fetching layer ontop of already mocking out the browser router. I just prefer functionality to be kept separate. I am much more excited for the Tanstack Router which is on the way.

    • @theuniverse685
      @theuniverse685 2 ปีที่แล้ว +4

      Exactly! And what about if you want to move to another library or framework... how complicated it could be! React Router is becoming a framework than just a a Router library. I mean, all those new features are really great but you can get stuck in the future

    • @Shyam_Mahanta
      @Shyam_Mahanta 2 ปีที่แล้ว +5

      Exactly they have done over engineering and most form submission is pretty useless for me. Since they are the same team who build remixJS & they are doing same thing with react router 6

    • @mistersunday_
      @mistersunday_ 2 ปีที่แล้ว +6

      Making design decisions based on your testing strategy is a bad habit and isn’t a user centric approach nor adds to DX. Moving your data to routes and you only render your component when the data is ready, leaves you with a way better experience. In fact, tanstack location already had this behavior and you can still combine this with tanstack query (in fact it’s the recommended caching strategy)

    • @mistersunday_
      @mistersunday_ 2 ปีที่แล้ว +2

      In fact, by decomposing your data layer from your component makes it more testable

    • @mattc16
      @mattc16 ปีที่แล้ว +3

      Ya, it’s not that you’re the minority but rather that you don’t understand it. React Query is a “caching” library. It doesn’t do data fetching. SWR is similar. React Router is offering a way to retrieve your data “before” your page renders, so it doesnt have to rerender on data load. I don’t understand the complaint. You should still use a caching library like React Query with React Router and data loaders.

  • @mustafamufeed1666
    @mustafamufeed1666 4 หลายเดือนก่อน

    in what section you added this lecture in the react course in udemy?

  • @TamirGilany
    @TamirGilany 2 ปีที่แล้ว +2

    Excellent and useful as usual!

  • @thomasnarkiss6319
    @thomasnarkiss6319 ปีที่แล้ว

    Were those 44 minutes video of React Router which don't include any* Link and/or NavLink components, or I just missed it..?
    (*Unless those components are no longer part of the concept..?)

  • @isholapinheiro
    @isholapinheiro ปีที่แล้ว

    Thank you this was incredibly helpful

  • @Wakkyguy
    @Wakkyguy 2 ปีที่แล้ว +2

    Hi Max,
    So if I don't use "defer" then React Router will always wait for the loader's promise to settle before loading the route page/component? Is there a way to get access to the the loading state when not using defer function?

  • @abdelhameedhamdy
    @abdelhameedhamdy 2 ปีที่แล้ว +5

    This exactly remix style to load data using hooks without touching useEffect

    • @mrX666-s9p
      @mrX666-s9p 2 ปีที่แล้ว +1

      Very shit and limiting stuff not a good practice.

  • @abdallahazouz5948
    @abdallahazouz5948 ปีที่แล้ว

    great discussion ,but I need to know how to make a condition inside createBrowserRouter , example :if I have a user logged in => so I can not go to login page

  • @johnniefujita
    @johnniefujita 2 ปีที่แล้ว +1

    Max I'm building the admin for an app and since it is for internal use. I'm experimenting on all these new approaches that I was eager to implement since I first heard about remix. They really hit the bullseye where things used to get really repetitive and unpleasant to work with react. My only doubt is what is the best state management solution for me to go for this new admin. I have stayed loyal to redux, the customer faced native app that I work for uses redux toolkit. What are your thoughts? should I experiment with something more focused just in central state management since async states are no longer a problem. What library do you think works better with this new router

    • @johnniefujita
      @johnniefujita 2 ปีที่แล้ว

      Maybe sticking to RTK but calling it postmortem synchronously to update the state is a reasonable call?

  • @solaaar3
    @solaaar3 ปีที่แล้ว

    how do you implement transition animation between routes in this new api, i'm having hard time figuring out how to do it.

  • @jerviemarquez5192
    @jerviemarquez5192 2 ปีที่แล้ว

    thank you so much Max 👍😁

  • @SonuSindhu
    @SonuSindhu 2 ปีที่แล้ว +1

    That's great addition 👍

  • @anton9410
    @anton9410 ปีที่แล้ว

    Would you please advise on how to implement the useRouteError() but in Typescript. It is defined as unknown and I have no idea how to define it in Typescript

  • @benyamineslami573
    @benyamineslami573 ปีที่แล้ว

    great tutorial, thanks

  • @omkarsalapurkar2981
    @omkarsalapurkar2981 ปีที่แล้ว +1

    This is exactly what remix does

  • @likewd9811
    @likewd9811 ปีที่แล้ว

    Great I always See your troturial

  • @srikanthchebrolu3333
    @srikanthchebrolu3333 ปีที่แล้ว

    is it possible to use polling with the new react router 6.4.2

  • @zubidev
    @zubidev 2 ปีที่แล้ว +7

    Please add this topic to the react course in udemy.

    • @academind
      @academind  2 ปีที่แล้ว +7

      We just sent an announcement regarding that + added a lecture.

    • @jz_s89zed19
      @jz_s89zed19 2 ปีที่แล้ว

      Thanks max!

  • @amitsinghrawat4760
    @amitsinghrawat4760 2 ปีที่แล้ว +1

    I think already have these features

  • @TakeOnMe5
    @TakeOnMe5 ปีที่แล้ว +1

    To be honest, I don't like the new data fetching stuff introduced in 6.4. Managing request/response logic at the routing level? I don't know what they smoked but React Router went beyond what its purpose originally was, namely client side routing only and just that. Luckily they didn't touch the regular mechanisms so one can still write clean client side routing code.

  • @andriisukhariev
    @andriisukhariev 2 ปีที่แล้ว

    Nice and explenative! But something is not working on version 6.4.2 - when i follow your instruction for "blog" and nested ":id" routes - blog shows up normally, but nested element is just blank ... could you advise on that? thanks

    • @andriisukhariev
      @andriisukhariev 2 ปีที่แล้ว

      Actually it works when i visit it clicking "Link" from react router, but when i visit page directly - it's blank

  • @ahmedbashir2307
    @ahmedbashir2307 2 ปีที่แล้ว

    Hey Max, any plan to launch new Laravel course?

  • @mj2068
    @mj2068 6 หลายเดือนก่อน

    damn. you are good at what you do. i wish i can be you.

  • @mistersunday_
    @mistersunday_ 2 ปีที่แล้ว +1

    Lessons learned from Remix 💿

  • @wadf29
    @wadf29 ปีที่แล้ว

    How about starting by setting the routes?

  • @esdev
    @esdev 2 ปีที่แล้ว +1

    Hey Max! What's your thought on @remix_run? Any plan to make a complete course?

  • @stavroskefaleas6320
    @stavroskefaleas6320 2 ปีที่แล้ว

    I am trying to convert an existing application to a react-router-dom v6.4 app and I am stuck.
    I have made the conversion of around the 80% of the app but I don't know where to put the Context API.

  • @sumonbarai178
    @sumonbarai178 ปีที่แล้ว

    really helpfull

  • @micheledellaquila7671
    @micheledellaquila7671 ปีที่แล้ว +1

    I found a problem with this new version: Uploading file. Action don't work with this type of form. Can anyone help me?

  • @daniel-n3v9j
    @daniel-n3v9j 2 ปีที่แล้ว +1

    Hello, can you please tell me how to create protected routes with v6.4? I have tried everything which i could find in youtube but nothing worked properly. So I would like to build a login system where only the login and the sign up pages are public. After I login, it redirects me to the home page and doesnt allow me to go back to the login page. Thanks...

    • @johnniefujita
      @johnniefujita 2 ปีที่แล้ว

      but was not it the proper behavior? keep register and login pages only when you are logged out? I'm starting to build using 6.4 now, when I get to that I may help you if I find it need some special dealing to solve. Have you figure it out for yourself already?

  • @enisjasarovic691
    @enisjasarovic691 ปีที่แล้ว

    Does anyone knows a good tutorial that implements some state management with React Router V6.4 and above... I can't figure out the best way to implement state management and which one to use

  • @balram1604
    @balram1604 2 ปีที่แล้ว

    is there a way to pass params to mapStateToProps redux? ownProps not working with version 6

  • @kawsarahmed7045
    @kawsarahmed7045 ปีที่แล้ว

    impressive

  • @alexanderbaltsevich9270
    @alexanderbaltsevich9270 ปีที่แล้ว +1

    is it strange only for me when router started fetching data and manage forms?

  • @mohamedyoussef8835
    @mohamedyoussef8835 ปีที่แล้ว

    Awesome video +++++++++++++ 🙂

  • @victorrochin2616
    @victorrochin2616 2 ปีที่แล้ว

    What if Im trying to go to a specific section of a page?

  • @khandokershahidujjamanshah8444
    @khandokershahidujjamanshah8444 ปีที่แล้ว

    in this tutorial, if I need a post image how to get a post image from fromData

  • @kumailn7662
    @kumailn7662 2 ปีที่แล้ว

    What about if error occurs in rendering?

  • @vanyamakhlinets7720
    @vanyamakhlinets7720 2 ปีที่แล้ว +5

    Don't understand this release. Community moving to hook declarative request strategy (react-query), new features are not compatible with such approach. Form handling looks awful too 🤨

    • @blessingz
      @blessingz 2 ปีที่แล้ว

      A complete un-learning of most the things that worked and kept the world round.

  • @AbdurrahmanASUR
    @AbdurrahmanASUR 2 ปีที่แล้ว +2

    👍👍🥰🥰

  • @IvanRandomDude
    @IvanRandomDude 2 ปีที่แล้ว +4

    Versioning makes no sense. You cannot have so many breaking changes in minor version. This should have been react router 7.Not professional at all. What's next, breaking changes in patches?

  • @DavidSmith-ef4eh
    @DavidSmith-ef4eh 2 ปีที่แล้ว

    Might be annoying to the users. Imagine clicking a link and nothing happens (since some data might take 400ms to load). I think it's better if the navigation happens right away, but to an empty page with a loader, instead of blocking the navigation for 400ms. I guess I am sticking with v5 forever then...

    • @sihoonkim1502
      @sihoonkim1502 2 ปีที่แล้ว +2

      I think this UX is a ton better cuz, when u transition from page 1 to page 2, with previous data fetching, it would navigate to page 2 instantly with no data, just spinners or skeleton UI. Now you can show the spinner with page 1, while data for page 2 is being fetched. So when the data arrives it navigates to populated page! So there will always be some meaningful data on the page during transition. In my opinion this does not only improve DX but also UX!

    • @DavidSmith-ef4eh
      @DavidSmith-ef4eh 2 ปีที่แล้ว +1

      @@sihoonkim1502 yes, but ties you in with react router. Suddenly it would be a pain to use that component in nextjs.

    • @sihoonkim1502
      @sihoonkim1502 2 ปีที่แล้ว +3

      ​@@DavidSmith-ef4eh Yea, I hate opinionated libraries and frameworks. I was worried about this as well when I first heard of this data fetching and mutation being included in the router. But the thing is, RR is not forcing u to use loaders and actions. They just give u "one more option" and the way they handle data fetching is really useful and I dont think u can do this with other data fetching tools or Next.js.
      Also with nested routes u can have parallel loaders being executed. All of this feels very "natural" that data fetching and mutation should be a part of the router.
      And with Next.js, I dont think it would make stuff necessarily a ton more difficult. The loader part would be similar with getServerSideProps. Also, they have Remix which is a SSR framework that uses the same RR 6.4 APIs. I would give that a try. I am trying it out recently, and really like it so far.

  • @devdive24
    @devdive24 ปีที่แล้ว

    Can anyone tell me how can I declare an index route for a parent route in v6.4 while using this format?
    const router = createBrowserRouter([
    {
    path: '/',
    element: ,
    },
    {
    path: '/login',
    element: ,
    },
    {
    path: '/dashboard',
    element: ,
    children: [
    {
    path: 'order',
    element: ,
    },
    {
    path: 'service-list',
    element: ,
    },
    {
    path: 'review',
    element: ,
    },
    ],
    },
    ]);

    • @donerlando9949
      @donerlando9949 ปีที่แล้ว

      If I understand your question correctly, it can be done like this:
      {
      index: true,
      component:
      }
      or:
      {
      path: '',
      component:
      }

  • @carefree_ladka
    @carefree_ladka 2 ปีที่แล้ว +2

    😞 why God. They're gonna run out of hooks names soon

  • @hakuna_matata_hakuna
    @hakuna_matata_hakuna 2 ปีที่แล้ว

    this just killed react-location , preloading with relay will be possible with react-router

  • @akshaygadekar3089
    @akshaygadekar3089 2 ปีที่แล้ว +2

    this is like total rewrite of react router dom

  • @downfall6223
    @downfall6223 2 ปีที่แล้ว +4

    React router is so bulky, fat and nasty. I need to implement a very simple functionality, but must go through this absolute behemoth of monolithic piece of crap. So many changes throughout the versions and such poor docs. Getting some random rerenders and component flickering and all that "good" stuff. I wish I just used next js for routing instead

    • @kayodedanprecious2053
      @kayodedanprecious2053 2 ปีที่แล้ว +3

      Just so annoying! The changes each version makes you feel like you don't know what you're doing.
      Reading their docs to find help is just futile!

  • @jacobgonzalez4746
    @jacobgonzalez4746 2 ปีที่แล้ว +3

    React router just killed react query?

  • @jaroslavhuss7813
    @jaroslavhuss7813 2 ปีที่แล้ว +3

    Making a React tutorial without TypeScript in 2022 is beyond me... Nobody writes a code in Javascript these days :/

    • @JBuchmann
      @JBuchmann ปีที่แล้ว +2

      Doing it in JS makes the code simpler for learning purposes. If you know TS then it's not hard to do that extra step yourself.

  • @chennurumanu
    @chennurumanu ปีที่แล้ว

    The video quality is not good. All blurry

  • @killDJuice
    @killDJuice ปีที่แล้ว

    kinda feels like angular tbh