Next.js App Router: Routing, Data Fetching, Caching

Поділитися
Вставка
  • Опубліковано 17 чер 2024
  • ‪@leerob‬, VP of Developer Experience at Vercel, explains new concepts and foundations of Next.js app router, including layouts, dynamic routes, and data fetching. Deploy today: vercel.fyi/app-router
    ⌛️ Timestamps:
    0:00 Introduction
    0:10 Routing
    2:57 Dynamic route segments
    4:53 Data fetching
    7:36 Caching
    11:42 Metadata
    💻 Resources:
    ◆ Routing: nextjs.org/docs/app/building-...
    ◆ Caching: nextjs.org/docs/app/building-...
    ◆ Metadata: nextjs.org/docs/app/building-...
    #vercel #nextjs
  • Наука та технологія

КОМЕНТАРІ • 311

  • @badalsaibo
    @badalsaibo Рік тому +18

    This was an excellent demo. Concise, brief and to the point. Thanks Lee!

    • @leerob
      @leerob Рік тому +2

      Thank you, this made my day 😁

  • @Vextor007998
    @Vextor007998 9 місяців тому +16

    This guide really answered almost all of my questions, it's short and straightforward. You're doing a great job.

    • @NobleOsinachi
      @NobleOsinachi 8 місяців тому +1

      Same thing I said. Like it was really packed with information and yet short.

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

    Love these new improvements. This is why I love Next JS ❤

  • @stillready6405
    @stillready6405 10 місяців тому +3

    I didn't know you have a UA-cam channel. I was trying for hours, reading the documentation and failed. And here you explain everything in just 15 minutes. Thank you for the video!

  • @ryanp787
    @ryanp787 Рік тому +31

    Love NextJS!!! Y’all are doing amazing innovative changes and I can’t wait for the app folder to be in production!! I’m hopping it’s coming in the near future. Keep up the great work team!!

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

      Literally, the only thing new was the last stuff with Metadata

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

      nothhing innovate ... it has been part of nuxt.js since for ever ...

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

      Its now stable!! Horray just as i got back to next js

    • @tabletuser123
      @tabletuser123 7 місяців тому +1

      Ai generated comment

    • @ryanp787
      @ryanp787 7 місяців тому +2

      @@tabletuser123 nope I’m real lol. Your account name looks AI generated

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

    thank you so much for this video, i am new to nextjs and i know noone that knows nextjs 13, so they couldnt help me with a problem i got with routing. but then you came!

  • @appscastle
    @appscastle 2 місяці тому

    This guy should keep posting videos, the examples and the way he explain things are just amazing

  • @mohamedheythembenhassen8337

    Thank you so much vercel and @leerob , very short and informative video , i really like the app directory .

  • @browsing1598
    @browsing1598 Місяць тому +1

    Dude you legit saved me. Was spending so much time on this. This is the only video that helped me

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

    i admit, this is truly fantastic! thanks to you amazing people of vercel and to you Lee, you're awesome.
    i'd love to know more to understand fully...

  • @NobleOsinachi
    @NobleOsinachi 8 місяців тому +33

    Bro just explained half of my Next JS problems in 15 mins! Wow! This guy is good! 👍👍👍

    • @user-vp6ig6vw4s
      @user-vp6ig6vw4s 18 днів тому

      beacuse it is by next js original channel

  • @christopheanfry2425
    @christopheanfry2425 Рік тому +6

    Love it make me want to use nextjs every single day. You’re an amazing team with an amazing product. Huge kudos for all of you and a special thank to you Lee for your videos

    • @leerob
      @leerob Рік тому +4

      Appreciate the kind words :)

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

    Very helpful!! Hope to see more videos like this!!

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

    used nextjs in my senior capstone project, it's blowing everyone away!

  • @mohitnagpal
    @mohitnagpal Рік тому +14

    I love Next.Js. Keep on going guys.

    • @leerob
      @leerob Рік тому +3

      Thank you!

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

    Currently using this in my next project and it’s so much easier to route between pages

  • @FrontendMedia
    @FrontendMedia 11 місяців тому

    Thanks! Those new features are really neat.

  • @advem.
    @advem. Рік тому

    Light years ago music was on vinyl records, then on CDs and now it's streamed from cloud.
    Movies were on VHS, later DVDs and BlueRays - now it's streamed from cloud.
    Video games... can't ever remember all those consoles but now it's all digital and also you can stream playing in cloud.
    Finally webApps - your UI had been rendering on your device's broweser for days or rendered server-side...
    ...until now.
    It's time for streaming era even in webdev with UI Streaming!
    Simply render component, cache or revalidate it and serve to clients! Just this tiny piece!
    FINALLY
    I am sooooo hyped for the stable release you can't image. Love what u doing guys

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

    very straightforward, love it

  • @farzadali7434
    @farzadali7434 Місяць тому

    Excellent delivery!

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

    Clear and to the point: thanks!

  • @tilmanmarquart8744
    @tilmanmarquart8744 Рік тому +2

    Super excited to use this in prod soon!😁

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

    Extremely helpful video, thank you!

  • @GowthamN-sp9wc
    @GowthamN-sp9wc 5 місяців тому

    Thank you for the info on how to route one page to another without a link tag.

  • @victorekea
    @victorekea 9 місяців тому +2

    This is a great refresher and summary of all the awesome features of the nextjs app directory. I'm curious if there are any implications of setting the cache: no-store parameter on the fetch keyword.

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

    this is BEAUTIFUL!!!!!

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

    Just what I needed, awesome!

  • @2an_sound
    @2an_sound 11 місяців тому +2

    Thank you! I'm not an expert in NextJS and in their docs for app router, couldn't find any mention of utilizing params to get the id from a dynamic route. I was messing with headers, pathname etc when params would have been fine. You helped me so much. Now I'm just trying to figure out why pages in my dynamic routes don't use the root layout (the page itself takes over the whole screen and the root layout is gone)

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

    Yes. This is very helpful. Thank you.

  • @AdeelEjaz
    @AdeelEjaz Рік тому +18

    I have been using app router for a few months on few of my production projects, and very impressed with the results. I'd love to see videos on how to implement GTM/GA, and posting data e.g. updating user details in a form.

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

      Great suggestions!

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

      Yeah this would be great, seems work on mutations is still ongoing for now…. But it seems the app directory is reaching stable, started a new SAAS project with it and hopefully it doesn’t end in tears 😂

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

    very well explained! just wow

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

    Amazing great work!

  • @faizanahmed9304
    @faizanahmed9304 Рік тому +5

    Thank you team vercel for explaining the concepts!

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

    This is the future of Web Developement!!!!

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

    Love the app directory, made my life so much easier!

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

      Glad to hear it!

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

      @@leerob Hey Lee, can you please share with us the VSCode theme that you were using during this video?

  • @emeraudata
    @emeraudata 4 дні тому

    You just have save my project before I turn crazy, tx comrade

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

    Amazing stuff ❤

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

    Brilliant innovations!

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

    Once the remaining router bugs are fixed, this will be amazing

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

    Full stack industry level application tutorial needed for all the best practices and application

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

    Next finally cracking Jekyll's layout feature 13 years later. But good demo of the data fetching behavior from Lee!

  • @iwantfrens5804
    @iwantfrens5804 6 місяців тому

    Leerob is fcking amazing!!! I love these videos!!!

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

    İt s been incredible helpfull. Thanks

  • @quickclean-ninja
    @quickclean-ninja Рік тому

    Great thanks..finaly i got it

  • @wfl-junior
    @wfl-junior Рік тому +1

    I can't wait to use the app directory stable

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

    Thanks for this amazing video

  • @harshilpatel3389
    @harshilpatel3389 11 місяців тому +1

    Finally i get the solution of routing. Huh. Please mention this specifically clear in the your website.

  • @oiojin831
    @oiojin831 8 місяців тому

    clear explanation

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

    Thanks Lee

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

    Please make a video on, Deployment. How to optimize and the proper way to deploy your app for the wild in new nextjs 13 way

  • @liketocode
    @liketocode Рік тому +2

    Wow, never been so happy to be told I have to re-write my code base ... what's NEXT ;)
    1) As has been asked below, how do we now define a list of paths for prerendering - previously done using getStaticPaths Method? The docs do not seem to detail this specifically?
    2) Observation - the generic naming convention for Page and API routes will make searching for files during development a bit of a task?
    Thanks a million - super framework.

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

      I'm learning NextJS at the moment and I have the same question about the generic naming convention. I opted for the old routing system because I want each file to have a more descriptive name.
      I'm still trying to understand the advantages of the new routing system, so if anybody can explain, please do it! thank you :)

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

    very helpful

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

    Like you said...it really blows my mind 😅 #Amazing

  • @sumitsaha6941
    @sumitsaha6941 3 місяці тому

    Keep going sir.

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

    Thank you for this video. It is so informative.
    I have one question for Lee, how does he get his cursor to move so smoothly?

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

    Thanks a lot

  • @exprove2496
    @exprove2496 Рік тому +9

    In 13:35 it's mentioned that "these are automatically deduplicated". If in getRepo was passed fetch({ cache: no-store }) would generateMetadata and Page make only one or two requests each refresh?

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

    Great 👍.

  • @RedVelocityTV
    @RedVelocityTV Рік тому +3

    I'd love to see a state management video for Next13. How server data can be hydrated on client to add interaction

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

      just pass props to a client component, that simple :)

    • @RedVelocityTV
      @RedVelocityTV Рік тому +2

      @@zuma206 large apps don't use prop drilling. They have their own client store

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

      @@RedVelocityTV I think you would just pass the props to the layout where it can hydrate the client store, just like with the current pages system

    • @najlepszyinformatyk1661
      @najlepszyinformatyk1661 11 місяців тому

      usually, you don't need to think about state management in an old-fashioned way, now all requests are cached by default so you just need to create the function `fetchSomeShit` and reuse it. For a client-based state, you can use old approaches as well

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

    Excellent to the point(s) video.
    Is there a code repo with the examples, so I can save time remixing and experimenting?

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

    The big thing here is being able to import npm packages like embedded tweets, unsplash images, etc, that do their own fetching on the server. The bad side is that the nesting is incredibly quirky, and waterfall-prone. If there's not enough education on the subject, the level of apps will reduce, and the number of new apps passing the performance criteria will reduce dramatically. The architecture allows for bad fetching. But well so does react-query, apollo client and friends.

  • @DrDarp
    @DrDarp 11 місяців тому

    For everyone wondering what icon pack it is, it's vscode-icons

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

    This is awesome. If my main data source is prisma, is there a way to leverage this caching mechanism, without losing the type safety provided by it?

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

    Video about auth with new Next would be nice. How to protect routes and such

  • @PeriklesPeriklesoglu
    @PeriklesPeriklesoglu 3 місяці тому

    thank you

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

    THANK YOU

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

    Hi, thanks for tutorial! What icon theme are you using here? :)

  • @user-qu8hg3wt3i
    @user-qu8hg3wt3i 4 місяці тому

    Thanks for sharing! I am confusing what different between images in source code and in public folder (performance, bundle size, ... ) and what is the best practice?

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

    I prefer nuxt. But yes this is the way. Strapi is one of my favs. Headless WP isnt anything to scoff at though.
    There are frameworks that exist solely for headless WP and with its extensions of plugins.

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

    Please also talk about how to share data between all these components with data being cashed on server, How to add styles. If there are any gotcha as it stands right now.

  • @Gyurmatag
    @Gyurmatag Рік тому +2

    What If I have some dynamic data on one route and I navigate to another route where I add to that data with a post request (for example a blog post) and If I navigate back to the previous route (without refresh) I want to see the fresh data list (post list) with the new item added? What can I use it to invalidate the cache and make Next.js to call the fetch again without refresh?

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

    What caught my attention was proposing type properties in Repository type definition. How VS Code have done that?

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

    Nice video! Could I know why every time when you type new lines of code, the "code hints" in grey colors already know what you are going to type? Any plugins abt this? Thx

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

    Not sure why Route Handlers were not showcased here. Seemed like a fitting topic

  • @prateekbagrecha7012
    @prateekbagrecha7012 9 місяців тому +1

    Could you please tell us the extensions that you are using to speed the development ?

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

    Thanks

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

    I wish you had kept going on and on explaining next js like sliding knife in butter.

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

    Great video
    When the app folder will be stable do you know the date ?

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

    helpful

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

    finally thanks

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

    So cool

  • @brahimo4701
    @brahimo4701 4 місяці тому

    is there a way to combine between getting the data from a server component and the use of "use hook" on the client component to avoid passing props??

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

    When experimenting with dynamic routes and looking at the x-vercel-cache header I noticed I only got a HIT on static routes, as soon as I used a dynamic route, like the blog post in the video, it resulted in a MISS. Why can I get the same level of caching on dynamic routes? Caching should be more dependent on the data on the page than the actual url.

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

    Is there a way to support static generation for dynamic routes similar to exporting fallback from getStaticPaths before next 13?

  • @TheAkshayvirle
    @TheAkshayvirle 11 місяців тому

    Which extension is used to predict all the async await fetch code generation that we see in the video?

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

    Is there a difference between no-cache, no-store and next.revalidate: 0?

  • @trevortylerlee
    @trevortylerlee Рік тому +4

    Had an issue where halfway through development we needed a page that we did not want to use the root layout. Seems like the only way to do that is to split that one page and the rest of the site into two separate folders in the app directory, each with their own layout. Tried doing that but as a result all my imports / paths broke.
    Is there an easier way to go about creating different root layouts? Or opting out of a root layout?

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

      I have been thinking the same, on how to out out of a certain layout for a specific page that is deeply nested. Like I would like to have root: layout work and layout level 2 work but I don't want layout level 1 to be included in the same route. Like how do I avoid that. Right Now The only way of doing it seems to be, not using layouts and instead use it as components that you can import like how we did it in the old nextjs.

  • @mathiasriissorensen6994
    @mathiasriissorensen6994 11 місяців тому

    I love this but I really miss a way to update the data when the user has interacted with an element, like updating their profile using a button.
    When using useSWR you can execute mutate(), and then the data is updating. Do we have something similar?

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

    Great content! I just wanted to ask, since fetch is the API that was extended to support some of this caching stuff, I'm guessing using something like axios it just won't support all of these features? Is there a way to make it work even with something like axios?

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

      I don't think so. If I'm not mistaken, you can use the new react cache function. That's the way to do it with database queries as well, I think.

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

      export const revalidate = 60 //one minute

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

      @@abdulramonlasisi3385 I'll have to try that out, but thanks. I was under the impression all of this requires fetch API to be used.

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

    The cache control, only works using the native fetch api ? or can I have the same behavior using axios for example?

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

    My next bigger project will be with Next.js.

  • @Steffi3rd
    @Steffi3rd Рік тому +4

    Awesome!!!
    Just have a question about generateMetaData :
    We need to do a getRepo twice (inside component and generateMetaData)
    I think it's a shame that we can't make this call only once to reuse the response of the getRepo in component for the generateMetaData...
    Isn't there another way to make a single network call?
    Thanks!

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

      Bingo! at least would take data from the Page params

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

    I love using the new app folder just need auth0 to update their next library for handling server side authentication. Currently it’s using the old router.

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

    Do I see an API folder in the app directory! Would’ve love to hear about that.

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

    Good brother

  • @0kJaymie
    @0kJaymie Рік тому

    Can you use anything other than [id] for your dynamic route folder? I tried using something else but it doesn't work. Maybe I'm doing it wrong but I'm not getting any errors

  • @AhmadMughal1
    @AhmadMughal1 8 місяців тому

    I have but one question which i am currently having an issue with and that is if the data is being cached and then we go to dynamic route such as blog/1 we can access the id through params but is there some way to use the data that exists inside the cache already to also be sent to that so i can access that data inside my dynamic routes or do i have to refetch the data again inside that dynamic route?

  • @qwerty-or1yg
    @qwerty-or1yg 4 місяці тому

    I'm using app router. What if I want to display a sidebar on all /blog/[id] pages and keep main layout for all other pages? I've tried creating a separate layout for /blog, but it seems to inherit root layout as well, so I'm not too sure what would best approach would be? Somehow conditionally render a layout depending on a route?

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

    Please do a video on NextJS SEO

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

    How would the app know how many ISR pages it has to store it statically first at build time?