Mastering Next.js Route Handlers: A Comprehensive Guide

Sdílet
Vložit
  • čas přidán 16. 08. 2023
  • In this in-depth tutorial, dive into the world of Next.js route handlers and learn how to take full control of your web application's routing. Discover the power and flexibility of Next.js route handlers as we explore dynamic routing, making API routes, and other useful techniques. Whether you're a beginner or an experienced Next.js developer, this comprehensive guide will provide you with the knowledge and practical examples you need to leverage Next.js route handlers effectively.

Komentáře • 32

  • @cloudagnostic
    @cloudagnostic Před 8 měsíci +2

    I love the way you explained the route handlers. I’ve watched many videos trying to explain what you did in 30+ minutes. I fully understand the process now. Thanks!

    • @coderyan
      @coderyan  Před 8 měsíci

      Happy to hear it helped!

  • @sh4vear
    @sh4vear Před 10 měsíci +1

    I've been waiting so long for this video and my guy just uploaded, great job👍🏻❤️🐐

  • @davidheimfert2816
    @davidheimfert2816 Před 7 měsíci +1

    Thanks for all your videos! I started my first Next commercial project, thinking something like "I know React and CRA, so let's go for it". I quickly got stuck on APIs, and discovered your channel thanks to this video. I put the project on standby while I watched your entire playlist, which was very well explained in a simple way.

    • @coderyan
      @coderyan  Před 7 měsíci

      You’re welcome! Happy to hear the videos are helping and best of luck on your project!

  • @toko385
    @toko385 Před měsícem

    Incredible as always 🔥 Thank You! 🚀

  • @Elias-xp3bs
    @Elias-xp3bs Před 7 měsíci +3

    Would be great if this video had timestamps :)

  • @tasfiqjawaad3757
    @tasfiqjawaad3757 Před 5 měsíci

    whats the purpose of using useRouter instead of redirect(21:34) on the view post button? Whats the difference? can anyone explain?

  • @volt4ge753
    @volt4ge753 Před 10 měsíci +1

    a really useful guide, thanks
    it would be better if you uploaded the final code to the git repo so that it can be quickly re-read without reviewing the video

    • @coderyan
      @coderyan  Před 10 měsíci

      Thank you and I appreciate the feedback. In future videos, I'm better about pushing the final code up to Github

  • @SuperYoda7
    @SuperYoda7 Před 10 měsíci +1

    nicely explained. Even to me it made all sense. Just one question. Isn't it better to have the components directory outside of the app router ? since if we have it inside we would effectively create new routes ending up with localhost:3000/components/ or doesn't it make a difference as long as we don't define a route or page file ?

    • @coderyan
      @coderyan  Před 10 měsíci +2

      Thank you! And it doesn’t actually matter. The only time a folder becomes public is when you add a route.js or page.js file within the folder

    • @SuperYoda7
      @SuperYoda7 Před 10 měsíci +1

      @@coderyan I see thanks, now I learned even more!

    • @coderyan
      @coderyan  Před 10 měsíci

      @SuperYoda7 happy to hear it!

  • @HigherStudyAspirant
    @HigherStudyAspirant Před 6 měsíci

    Thanks for detailed explanation. but I have one confusion, what is the need of route handler when we can do the same thing from server components and client components.

    • @coderyan
      @coderyan  Před 6 měsíci

      Great question. And most of the time, you shouldn’t need to use a route handler. But there are situations where they’re useful. For example, if you update your database in a client component and want to revalidate the cache, you make make an API request to a route handler to revalidate the cache for a certain path

  • @carlotubigon8763
    @carlotubigon8763 Před 4 měsíci

    @Code Ryan Why is it needed to fetch it from route handlers first 24:04 before fetching it in posts page? Is it not possible to fetch it directly in posts page without the route handler?

    • @coderyan
      @coderyan  Před 4 měsíci +1

      Yeah that’s probably fine. But this video is covering route handlers so just showing how they work

    • @carlotubigon8763
      @carlotubigon8763 Před 4 měsíci

      @@coderyan I see, I just want to know when to use the route handlers and when to use in-page fetch. There may be some advantages/disadvantages between the two. Do you know any?

  • @prashlovessamosa
    @prashlovessamosa Před 10 měsíci +1

    Thanks

  • @Rotanakkosal
    @Rotanakkosal Před 7 měsíci

    I have an question? Since we can get data with fetch method, so why we need route hander ?

    • @joseernestoroldan
      @joseernestoroldan Před 6 měsíci

      to create endpoints so you can create your own resources api.

  • @stanleychukwu7424
    @stanleychukwu7424 Před 10 měsíci

    thank you boss! hi beautiful dog, you about to go for a walk!

  • @mohanram18
    @mohanram18 Před 10 měsíci +1

    still don't understand the logic for not allow to create route.ts at the same route segment

    • @coderyan
      @coderyan  Před 10 měsíci

      I’m not entirely sure I understand what you mean, could you maybe rephrase your question?

    • @mohanram18
      @mohanram18 Před 10 měsíci

      @@coderyan Nextjs uses the convention of page.tsx to serve a route, so the same way route handler has a convention of route.ts , page.tsx and route.ts can co-exist on the same level, But Nextjs does not allow at the same level.

    • @muhammadparacha
      @muhammadparacha Před 3 měsíci

      @@mohanram18 Yep, you're going to have to nest the route.ts in ./api/ or /app/api/...