Mastering Next.js Route Handlers: A Comprehensive Guide

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

КОМЕНТАРІ • 35

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

      Happy to hear it helped!

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

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

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

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

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

    Incredible as always 🔥 Thank You! 🚀

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

      You’re welcome!

  • @Elias-xp3bs
    @Elias-xp3bs 8 місяців тому +3

    Would be great if this video had timestamps :)

  • @erreyonj
    @erreyonj 6 днів тому

    Thanks super helpful vid!!

  • @volt4ge753
    @volt4ge753 Рік тому +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  Рік тому

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

  • @emmanueldjambatambashe701
    @emmanueldjambatambashe701 22 дні тому

    can you give me the resource that you use?

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

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

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

    Thanks

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

    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  8 місяців тому

      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

  • @SuperYoda7
    @SuperYoda7 Рік тому +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  Рік тому +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 Рік тому +1

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

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

      @SuperYoda7 happy to hear it!

  • @Rotanakkosal
    @Rotanakkosal 9 місяців тому

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

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

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

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

    @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  6 місяців тому +1

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

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

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

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

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

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

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

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

      @@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 4 місяці тому

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

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

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