React Router 6.4 - Getting Started

Поділитися
Вставка
  • Опубліковано 25 лис 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.

  • @transfer1992
    @transfer1992 Рік тому

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

  • @ChrisBrown-si1vg
    @ChrisBrown-si1vg Місяць тому

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

  • @pyrocentury
    @pyrocentury 2 роки тому +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 😐

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

  • @krtrvi
    @krtrvi Рік тому

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

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

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

  • @shotgun600
    @shotgun600 Рік тому

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

  • @skoodath
    @skoodath 2 роки тому +1

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

  • @TamirGilany
    @TamirGilany 2 роки тому +2

    Excellent and useful as usual!

  • @omarkarim9298
    @omarkarim9298 2 роки тому +9

    Angular has had this since v2 with guards

    • @mkru37
      @mkru37 2 роки тому

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

  • @ktoscos4546
    @ktoscos4546 10 місяців тому

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

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

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

  • @deepakbhatt7494
    @deepakbhatt7494 2 роки тому

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

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

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

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

  • @ktoscos4546
    @ktoscos4546 10 місяців тому

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

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

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

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

  • @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. 9 місяців тому +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

  • @mustafamufeed1666
    @mustafamufeed1666 5 місяців тому

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

  • @isholapinheiro
    @isholapinheiro 2 роки тому

    Thank you this was incredibly helpful

  • @micheledellaquila7671
    @micheledellaquila7671 2 роки тому +1

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

  • @abdallahazouz5948
    @abdallahazouz5948 2 роки тому

    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

  • @omkarsalapurkar2981
    @omkarsalapurkar2981 Рік тому +1

    This is exactly what remix does

  • @ed-jamal
    @ed-jamal 2 роки тому +1

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

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

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

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

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

  • @jeffkinley3698
    @jeffkinley3698 2 роки тому

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

  • @mistersunday_
    @mistersunday_ 2 роки тому +1

    Lessons learned from Remix 💿

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

  • @srikanthchebrolu3333
    @srikanthchebrolu3333 2 роки тому

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

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

  • @wadf29
    @wadf29 Рік тому

    How about starting by setting the routes?

  • @amitsinghrawat4760
    @amitsinghrawat4760 2 роки тому +1

    I think already have these features

  • @alexanderbaltsevich9270
    @alexanderbaltsevich9270 Рік тому +1

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

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

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

  • @benyamineslami573
    @benyamineslami573 Рік тому

    great tutorial, thanks

  • @victorrochin2616
    @victorrochin2616 2 роки тому

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

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

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

  • @ahmedbashir2307
    @ahmedbashir2307 2 роки тому

    Hey Max, any plan to launch new Laravel course?

  • @likewd9811
    @likewd9811 Рік тому

    Great I always See your troturial

  • @BalramTheExplorer
    @BalramTheExplorer 2 роки тому

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

  • @esdev
    @esdev 2 роки тому +1

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

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

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

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

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

  • @mj2068
    @mj2068 7 місяців тому

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

  • @sumonbarai178
    @sumonbarai178 2 роки тому

    really helpfull

  • @akshaygadekar3089
    @akshaygadekar3089 2 роки тому +2

    this is like total rewrite of react router dom

  • @kawsarahmed7045
    @kawsarahmed7045 2 роки тому

    impressive

  • @mohamedyoussef8835
    @mohamedyoussef8835 Рік тому

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

  • @devdive24
    @devdive24 2 роки тому

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

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

    👍👍🥰🥰

  • @carefree_ladka
    @carefree_ladka 2 роки тому +2

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

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

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

  • @hakuna_matata_hakuna
    @hakuna_matata_hakuna 2 роки тому

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

  • @chennurumanu
    @chennurumanu 2 роки тому

    The video quality is not good. All blurry

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