Next.js App Router Multiple Root Layouts: Explained With Examples

Поделиться
HTML-код
  • Опубликовано: 4 ноя 2024

Комментарии • 161

  • @kenkioqqo
    @kenkioqqo 6 месяцев назад +9

    Absolutely awesome! You started by describing the exact mistake I was making while trying to create a different layout for my dashboard, and then you provided a wonderful solution that works like a charm. I can't thank you enough for this tutorial.

  • @klebergermano3356
    @klebergermano3356 2 месяца назад +2

    I was racking my brains over this, thanks a lot for the clear explanation, really helpful

  • @thebenkalungi
    @thebenkalungi 4 месяца назад +2

    Thanks for the clarity... Been facing this route problem since yesterday and almost gave up but your video has saved me.

  • @mateomohr3415
    @mateomohr3415 4 месяца назад

    FINALLY I FOUND THE VIDEO TO SOLVE MY PROBLEM, TY TAPAS. THE EXPLANATION COULDNT BE ANY BETTER

    • @tapasadhikary
      @tapasadhikary  4 месяца назад

      You are most welcome.. I am so glad that my video helped you... super happy ❤

  • @ZeynalZeynalli-yo2nl
    @ZeynalZeynalli-yo2nl 2 месяца назад

    you are life saver sir. awesome video for those who dont want to read the docs.

  • @jahangirkhan3747
    @jahangirkhan3747 8 месяцев назад +1

    Ur way of explaining the concept is awesome sir ❤❤❤

    • @tapasadhikary
      @tapasadhikary  8 месяцев назад +1

      Thanks a lot, keep learning 👍

  • @snow-script
    @snow-script 7 месяцев назад +1

    Your every video is going outstanding many different things but I think just for a recap of the last moment. 💕💕

  • @metadope9407
    @metadope9407 3 месяца назад +1

    Thanks Tapas da...you always shows all the edge cases...you're an awesome teacher❤

  • @prateekshawebdesign8377
    @prateekshawebdesign8377 3 месяца назад

    Great video! Your explanation of multiple layouts in Next.js was clear and practical. The examples were easy to follow and very helpful.

    • @tapasadhikary
      @tapasadhikary  3 месяца назад

      @@prateekshawebdesign8377 So glad to hear that ✨🔥

  • @guvenfazli
    @guvenfazli 11 дней назад +1

    Thank you sir.

  • @AlexanderWilson-ht5dt
    @AlexanderWilson-ht5dt 2 месяца назад

    Great explanation on Next.js route grouping! Astro.js has a very similar approach, and it's really helpful to see how both frameworks handle this. This video was super helpful in deepening my understanding-thanks for sharing!

    • @tapasadhikary
      @tapasadhikary  2 месяца назад

      @@AlexanderWilson-ht5dt most welcome ✨

  • @wasiuddinmansoori3385
    @wasiuddinmansoori3385 4 месяца назад

    The way you explained is very insane and informative. Sooo much informative content. ♥

  • @AngelaCui-fn2tn
    @AngelaCui-fn2tn 2 месяца назад +1

    Thank you so much for sharing your knowledge!

  • @froilanimnida
    @froilanimnida 3 месяца назад

    straightforward video, does the thing i wanted to know. thanks!

  • @shraj340
    @shraj340 5 месяцев назад +3

    The exact thing I wanted

  • @ravitokas84
    @ravitokas84 Месяц назад +1

    Thanks tapas for sharing this video.

  • @Learexx
    @Learexx 2 месяца назад

    I really needed this, thank you sir

  • @joaoarthurbandeira
    @joaoarthurbandeira 3 месяца назад +1

    Great video! Question: could i leave a layout.tsx file in the root level only wrapping the children with html, body and say GoogleTagManager tags while also having, at the same time, layout.tsx files for each route grouping, so i dont have to put these tags on each of them? In this case, would this root level layout.tsx file wrap all of the other layouts with these tags and work? Thanks!

    • @joaoarthurbandeira
      @joaoarthurbandeira 3 месяца назад

      I tested here and it still worked and also it also stopped the whole page from getting reloaded when navigating between these route groups, i guess because now they share the same html tag. Does this make sense or am i missing something and should not do this?

    • @tapasadhikary
      @tapasadhikary  3 месяца назад +1

      Yes it will work… do not repeat the html and body in child layouts.

    • @joaoarthurbandeira
      @joaoarthurbandeira 3 месяца назад +1

      @@tapasadhikary Thanks! Is this approach better since it has the same benefits but it doesnt force reload when navigating between these route groups or does it have any cons?

    • @tapasadhikary
      @tapasadhikary  3 месяца назад +1

      @joaoarthurbandeira yep great approach

  • @codewithnarutos
    @codewithnarutos 13 дней назад

    Thank you, absolutely awesome!

  • @Matunga
    @Matunga 6 месяцев назад +1

    Awesome explanation! Thanks a lot

  • @emmanuelsalami3257
    @emmanuelsalami3257 5 месяцев назад

    you just got a new subscriber sir.. you are a genius

    • @tapasadhikary
      @tapasadhikary  5 месяцев назад

      Thanks, man. It means a lot ❤️

  • @boot-comp
    @boot-comp 3 месяца назад

    perfect explanation thaanks

  • @MrTingle-qi2ne
    @MrTingle-qi2ne 3 месяца назад

    My trouble is not knowing how to achieve route grouping but with dynamic slugs ( [...slug] ), because obviously this confuses the system. I've tried everything but still can't figure out how to get the Root Layout to distinguish between header/noheader based on CMS data. I can do it by putting headers inside sub-layouts instead (as sub layouts can receive the slug array) but that unfortunately re-renders the header every time the route changes (problematic for preserving header state). I don't actually think there is a clean solution to this beyond designating a hardcoded no-header sub route. Anyway... easy enough for me to manually make per-project specific folders in src/app to manage this, but I was dreaming up a pure CMS driven solution :(.

  • @ederross
    @ederross 6 месяцев назад

    AMAZING! PERFECT! THANKS A LOT FROM THE BOTTOM OF MY HEART!

    • @tapasadhikary
      @tapasadhikary  6 месяцев назад

      Wow… thanks a lot ❤️. Don't forget to subscribe 😉, much more coming!

  • @md.mojnumiah
    @md.mojnumiah 8 месяцев назад +1

    thanks for sharing, vai.

  • @MailsonVarela-on7we
    @MailsonVarela-on7we 5 месяцев назад

    saved my day!
    thanks for the explaination

    • @tapasadhikary
      @tapasadhikary  5 месяцев назад

      Thanks mate, for letting me know. You are most welcome.

  • @ghimirerahul39
    @ghimirerahul39 Месяц назад

    thanks bro for this awesome video and awesome explaination

  • @DuK-2102
    @DuK-2102 4 месяца назад +1

    This solved my problem but there is 1 more issue occured. How do you make a not-found page for this multiple root layouts? Even if I put not-found.tsx file in both (auth) and (home) folder, when go to wrong url, the browser render not found page from default nextJS itself not from my not-found.tsx file.

    • @tapasadhikary
      @tapasadhikary  4 месяца назад +1

      Thank you! Let me cover not found and error in a video

  • @langchats
    @langchats День назад

    There have another issue, after using route group, when we are trying to navigate then the page is re-loading like a normal html and then loading another page. but we expect navigation behavior without any refresh. can you please tell me how we can fix it?

  • @ilyahuman7565
    @ilyahuman7565 7 месяцев назад +2

    Hi there! ChatGPT tells me that it is not required to put html and body tags into RootLayout, cause since Next.js13 it is automatically. But I cannot see this in next doc. Any ideas?)

    • @tapasadhikary
      @tapasadhikary  7 месяцев назад

      Me neither. Your web document needs the root HTML to render and to do many other things including the locale support.. So there must be at least one root layout where the HTML tag should be there.. Not sure about the chatGPT suggestion, though...

  • @YashKadam-k5q
    @YashKadam-k5q 6 месяцев назад +1

    Hot reloading is only working for the (home) group and not for other groups. Additionally, I have react-hook-form implemented in other groups, and the same issue occurs: it's only working in the (home) group and not in other groups.

    • @tapasadhikary
      @tapasadhikary  6 месяцев назад

      Try removing the .next folder and restart the local server.

  • @Daniel-Y72
    @Daniel-Y72 Месяц назад +1

    Do I have to add html & body tag to other layouts as well? Because if I don't, it gives the `Missing Root Layout Tags` error.

    • @tapasadhikary
      @tapasadhikary  Месяц назад +1

      @@Daniel-Y72 no not needed..for that error seem to be the issue with the layout hierarchy

    • @wforbes87
      @wforbes87 Месяц назад

      today's nextjs version '14.2.13' gives this error modal pop-up. while the version that this video was created with (14.1.2) does not. clone his repo and see the difference

  • @magehdinc
    @magehdinc 3 месяца назад

    Brilliant Tutorial!

  • @SyedSINA
    @SyedSINA 5 месяцев назад +1

    Thanks for the solution,
    There is still one little problem that the whole page gets reloaded when navigating between these route groups. For example, when a user navigates between HomeLayout routes and MarketingLayout routes whole page gets reloaded. How can I stop reloading whole page and only redirect on client side?

    • @tapasadhikary
      @tapasadhikary  5 месяцев назад

      Where do you see the reload? In the example project I shared with the video? Or in your project?

    • @SyedSINA
      @SyedSINA 5 месяцев назад +1

      @@tapasadhikary
      In my project, I have two route groups that has separate layouts. When I navigating between routes of these two layouts the full page reload happens. This is mentioned in the Next.js docs too. But I didn't find an elegant solution to do it without full page reload

    • @tapasadhikary
      @tapasadhikary  4 месяца назад

      @@SyedSINA got it. Yes, this happens. Do you have a main root layout apart from these parallel route layouts?

    • @SyedSINA
      @SyedSINA 4 месяца назад

      ​@@tapasadhikary No, there is no main root layout in the root folder. I followed the structure exactly like in the video. In my project, it looks like this:
      (booking) -> booking -> [layout.tsx, page.tsx]
      (default) -> [layout.tsx, page.tsx]
      When navigating from '/' to '/booking', a full reload happens. I am aware that the Next.js documentation mentions this issue, but it would be better to have something like the getLayout method from Next.js 12 in this version as well.

    • @mostafizurrahman4340
      @mostafizurrahman4340 3 месяца назад

      ​@@SyedSINABro did you manage to solve this problem.

  • @TALDR27
    @TALDR27 2 месяца назад +1

    Thank you man!

  • @java427
    @java427 6 месяцев назад +1

    Awesome video! Thanks

  • @aroshasandaruwan3667
    @aroshasandaruwan3667 Месяц назад +1

    clearly explained.

  • @mdsumonh.shohan9159
    @mdsumonh.shohan9159 2 месяца назад

    tapash vai in my code on marketing route does not run without html and body tags in marketing RootLayout.

  • @VivekSpecscart
    @VivekSpecscart 7 месяцев назад

    Hi sir, i have get error when I create (home) folder and move "app/layout.tsx" and ''app/page.tsx' files in the folder, can you please check?
    How can I connect with you?
    please help 🙏

  • @naufui
    @naufui Месяц назад

    Thank you so much!

  • @imdefnotash
    @imdefnotash 3 месяца назад

    UFF thank god you helped me!

  • @samshan813
    @samshan813 5 месяцев назад

    Thanks for the video ,, but there is error comes on jsconfig.json, could you please advise

    • @tapasadhikary
      @tapasadhikary  5 месяцев назад

      What error? Also have you restarted VS code and saw if the error still there?

  • @smselva9324
    @smselva9324 2 месяца назад +1

    How to handle redux setup with multiple layouts Sir

    • @tapasadhikary
      @tapasadhikary  2 месяца назад

      You should do it at the client side.

  • @aburaihan-py4vi
    @aburaihan-py4vi 8 месяцев назад +1

    Excellent!!!!!!

  • @kaioneal6160
    @kaioneal6160 5 месяцев назад +1

    Finally
    Thank you 🙏

  • @Phonebangla
    @Phonebangla Месяц назад

    use this method why global.css not applicable for child component pages ?

  • @HasanAhmedNews
    @HasanAhmedNews 15 дней назад

    thankyou Tapas Vai

  • @muhammadinaammunir6761
    @muhammadinaammunir6761 3 месяца назад +1

    Good content

    • @tapasadhikary
      @tapasadhikary  3 месяца назад

      @@muhammadinaammunir6761 thanks a lot ❤️

  • @ItsKrishnaPanthi
    @ItsKrishnaPanthi 4 месяца назад

    Need to add html and body tag to the marketing route layout as well, other wise browser error pops up saying tags missing in the Root Layout.

    • @tapasadhikary
      @tapasadhikary  4 месяца назад

      Do you get it as an Hydration error?

    • @ItsKrishnaPanthi
      @ItsKrishnaPanthi 4 месяца назад +1

      @@tapasadhikary It's not an hydration error. Nextjs docs says html and body tags need to be added to each root layout. Maybe some kind of latest requirement.

    • @tapasadhikary
      @tapasadhikary  4 месяца назад

      @@ItsKrishnaPanthi Got it, thanks!

  • @nahid_ulkabir8240
    @nahid_ulkabir8240 5 месяцев назад +1

    I canot use any react hook like useState inside /marketing page . not event a console is working on that page . please help me , I want a client component on that page

    • @tapasadhikary
      @tapasadhikary  5 месяцев назад

      It is because the marketing page is a server component and you can not use the client side things like React Hooks in the server component. The design pattern you must follow is, take out the client interaction part separately in a separate client component where you can use all the hooks and make sure to use the "use directive" for client component. After that import the client component to the marketing page server component...
      It is important to understand how you should compose your server and client components for a better results including the SEO of the app.
      I hope it helps.

    • @nahid_ulkabir8240
      @nahid_ulkabir8240 5 месяцев назад +1

      @@tapasadhikary thank you very much

  • @codeWithSleek
    @codeWithSleek 15 дней назад

    Thank you!

  • @najmulislam344
    @najmulislam344 6 месяцев назад +1

    very very helpful

  • @sarangsami6597
    @sarangsami6597 6 месяцев назад

    you saved my life

  • @Anguraj92
    @Anguraj92 8 месяцев назад +1

    Nice sir

  • @omarrayes2281
    @omarrayes2281 6 месяцев назад +1

    is this the only solution ? for doing that ? please if there something else give a link to read . And Thanx

    • @tapasadhikary
      @tapasadhikary  6 месяцев назад

      This is what I found as one solution… the other solution is to get the pathname from route and based on path name you show hide things. For that you have to make the components client components forcefully.

  • @dhananjaygupta8554
    @dhananjaygupta8554 Месяц назад +1

    Thanks ❤

  • @ericsiddiq7634
    @ericsiddiq7634 8 месяцев назад +1

    nice tricks!

  • @darkx6916
    @darkx6916 5 месяцев назад +1

    Legend Tapas 🗿

  • @nelsonkc4703
    @nelsonkc4703 12 дней назад

    but in local it is shwoing gittering issue when i switch between layout thought somehow that layout shares most of same content .but this issue is not in live

  • @clearface123
    @clearface123 7 месяцев назад +1

    does this mean we have to duplicate the providers across every layout

    • @tapasadhikary
      @tapasadhikary  7 месяцев назад

      Nope, you can providers common and reuse across the layouts.

  • @davittchike
    @davittchike Месяц назад

    im stuck both of the layouts get rendered pls help

  • @EverydayBeing-de1qu
    @EverydayBeing-de1qu 5 месяцев назад +1

    Thank you

  • @pspremshakti1083
    @pspremshakti1083 4 месяца назад

    But in this technique the page is reloading

  • @DeveloperJunaid
    @DeveloperJunaid 6 месяцев назад +1

    Zabardast

  • @igorr4682
    @igorr4682 4 месяца назад +1

    and you forgot to mention that if you do this, this will do full pager render if you go from one layout to the other

    • @tapasadhikary
      @tapasadhikary  4 месяца назад

      Yep that happens, true. Mentioned in doc too… good point.

  • @Abhishekbhat-p6d
    @Abhishekbhat-p6d 7 месяцев назад

    Solved many problems especially in authenticated and not authenticated route

  • @rustan-e3
    @rustan-e3 22 дня назад

    But the app root need to have a layout?

  • @AlexRankin-gi1tl
    @AlexRankin-gi1tl 6 месяцев назад

    Life saver!

    • @tapasadhikary
      @tapasadhikary  6 месяцев назад

      So glad, Alex that it helped you! Thanks.

  • @deepakbind6774
    @deepakbind6774 3 месяца назад +1

    and what about not-found page

    • @tapasadhikary
      @tapasadhikary  3 месяца назад

      It is simple. Include a not-found.tsx or not-found.jsx file along with the layoout.jsx or layout.tsx file for each layouts. Whenever a notFound() exception is throws from the route the respective not-found page would be taking care of it.

  • @saimundev
    @saimundev 6 месяцев назад

    when I declare a route link with href the page is reloaded.. how to solve this??

    • @tapasadhikary
      @tapasadhikary  6 месяцев назад

      What’s the href value?

    • @itsearcast
      @itsearcast Месяц назад

      @@tapasadhikary lets take an example---"(home) (dashboard) when I am navigating from dashboard to home using the navigation is working correctly but it is causing the page reload

  • @ChickenChaap
    @ChickenChaap 4 месяца назад +1

    love it

  • @joaopaulosantana815
    @joaopaulosantana815 7 месяцев назад +1

    🚀🚀🚀🚀

  • @arifulhaque3236
    @arifulhaque3236 8 месяцев назад +1

    ❤❤

  • @evgeny9945
    @evgeny9945 Месяц назад +1

    best

  • @abujayed8999
    @abujayed8999 7 месяцев назад +1

    Sir, You have no idea what level of video is it. sub.

    • @tapasadhikary
      @tapasadhikary  7 месяцев назад +1

      Glad you liked it… keep learning 🫶

  • @იოსებივარდოშვილი

    gg

  • @SabarangChakma
    @SabarangChakma 8 месяцев назад +1

    বাংলায় কোর্স চাই.... ইংরেজি সবার বোধগম্য নয়

    • @tapasadhikary
      @tapasadhikary  8 месяцев назад

      কি বলি বলুন তো ভাই। আমি আপনার সাথে already সহমত। tapaScript বাংলা চ্যানেলের promotion ও শুরু হয়ে গেছে, আর সেটা এসেও যাবে আর ১-২ সপ্তাহে।
      কিন্তু তবুও আমি আনুরধ করবো ইংরেজি ভিডিও দেখে আসতে আসতে শেখার। দুটোই চলুক। আপনি বাংলাতে শিখবেন, ইংরাজিতেও শিখবেন। অসুবিধা হলে জিজ্ঞাসা করে নেবেন... হেল্প করবো।
      আশা করি আপনি আমার দুটো চ্যানেলকেই সাপোর্ট করবেন। 😀😍

  • @neeraj-u6e
    @neeraj-u6e Месяц назад

    Wwwoooowwwwwwwwwwwwww

  • @SDEC-f7b
    @SDEC-f7b 6 дней назад +1

    Thank you !

  • @PeriklesPeriklesoglu
    @PeriklesPeriklesoglu 3 месяца назад +1

    thank you

  • @PeriklesPeriklesoglu
    @PeriklesPeriklesoglu 3 месяца назад +1

    thank you