Next.js Modal Routing

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

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

  • @paulofernandoee
    @paulofernandoee Год назад

    I was serching all over the internet to see a use of the "as" path, with you i finally got it! Thanks a lot 😁

  • @RyanRampersad
    @RyanRampersad 2 года назад +2

    Thanks for the video. I never knew that `Link` took an `as` prop - and if I had seen it in the docs I would have assumed it was for changing its internal element. Very useful.

  • @ThugLifeModafocah
    @ThugLifeModafocah 2 года назад

    In a very short video you just "saved my life". Thank you.

  • @jimshtepa5423
    @jimshtepa5423 2 года назад

    Thanks to Sam's reference I found your channel. Thank you for this kind of high quality content!

  • @yuumeko_yt
    @yuumeko_yt 2 года назад

    Nextjs modal using headless UI! You save my life ^^
    Every tutorial used react modal and not headless ui
    I was starting to lose hope. Thank you so much !

  • @ashatron656
    @ashatron656 2 года назад +25

    I'm a very experienced next dev, this vid is super clear, straight to the point, and nicely presented.
    The video quality is well beyond your sub count. Keep it up and you'll have thousands of subs! 👍

    • @RyanToronto
      @RyanToronto  2 года назад +1

      Thanks so much for the kind words! Glad you enjoyed the video.

    • @aleksandrv2646
      @aleksandrv2646 Год назад

      @@RyanToronto Thanks for this video! Do you know how to implement the same with NextJS 13?

    • @RyanToronto
      @RyanToronto  Год назад +2

      @@aleksandrv2646 Hi there! So Next 13 will eventually support route intercepting. See this link in the original RFC: nextjs.org/blog/layouts-rfc#intercepting-routes
      The idea is that you would intercept routes to the photos page and instead show the photo in a modal. I don't think route intercepting works today, but keep your eye out for it!

  • @andrei-victor
    @andrei-victor 4 месяца назад

    Nice . Thank You!
    I'm using it in a list-feed and I wanted to maintain the scroll position, so I've added `scroll={false}` prop to the Link component and also`router.push("/", undefined, {scroll: false});` on modal close.

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

      Oh awesome! That's great to know!

  • @saddacracker
    @saddacracker Год назад

    Very helpful! After reading a couple articles (and the docs) this helped me put the pieces together. Thank you!

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

    Thx man!! A few changes with Next, but still working

  • @joshdale
    @joshdale 2 года назад

    Great video Ryan. I had no idea Next could do this. Super cool!

  • @cricket_canada5219
    @cricket_canada5219 2 года назад

    Today i learned something new! Thank you for creating this video. Super helpful.

  • @mryechkin
    @mryechkin 2 года назад

    This is awesome! Neat pattern, I'll have to keep it in mind.

  • @Eutohius
    @Eutohius 2 года назад

    Love the video man, exactly what I needed

  • @Moh_ha
    @Moh_ha Год назад

    Thanks cof sharing very useful!

  • @karsongrady
    @karsongrady Год назад

    Amazing content as per usual. I really appreciate it!

  • @joakimwretlind4016
    @joakimwretlind4016 2 года назад

    This is awesome! Thank you very much for the great info presented in a great way!

  • @orubenlopes
    @orubenlopes Год назад

    Perfect tutorial video! Thanks!

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

    I wish folks could use example examples outside the doc examples

  • @felipemarinho1326
    @felipemarinho1326 11 месяцев назад +2

    How to achieve this with app router ?

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

    Hi Ryan, it's a very instructive video. Cloud you please clarify how ISR feature will work for Modal?

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

      Hey there! I think ISR should work with the modal. If the homepage or an image changes you'd need to ISR both pages.

  • @erikplachta
    @erikplachta Год назад

    Great video, thank you for this.

  • @devmeraz87
    @devmeraz87 Год назад

    Thanks a lot 😊😊

  • @Tech_Ez
    @Tech_Ez 9 месяцев назад

    Great vid my guy.

  • @krimod
    @krimod 2 года назад

    awesome video, thank you !!

  • @mi1ami1a32
    @mi1ami1a32 Год назад

    Thank you!

  • @timothysteele4828
    @timothysteele4828 2 года назад

    Please can you a video that will allow one to edit data in modal Nextjs

  • @someonewhowantedtobeahero3206
    @someonewhowantedtobeahero3206 2 года назад

    i was just wondering the other day how Reddit does its modal rendering for posts. Thanks for sharing.

  • @kameleddineayache8756
    @kameleddineayache8756 2 года назад

    great video !

  • @AJPHIL-bt4me
    @AJPHIL-bt4me 2 месяца назад

    Gonna see if this can work for videos

  • @juliscapucin
    @juliscapucin 2 года назад

    Thanks a lot!

  • @nick-ui
    @nick-ui Год назад

    Hello, Ryan!
    It's seems that video kinda old but idea is still cool. I have a question, what if we have thousand images and because of static generation we will have like 10,20 minutes build time. It's cost a lot money for us. So what will be better?

    • @RyanToronto
      @RyanToronto  Год назад +1

      Hi there! Yes build times can get long when you have that many pages! One thing you could try is only build static pages for your top 100 or so pages. For the other thousands of pages you can build them only at request time using `fallback: "blocking"`.
      Check out the docs on fallback here: nextjs.org/docs/pages/api-reference/functions/get-static-paths#fallback-blocking
      The nice thing about this approach is you statically build your most popular content, but you keep your build times controlled by limiting the number of pages your process at build time. You less popular content is still statically buildable, but it only happens after the first request comes in.

  • @Danicarmonaserrat
    @Danicarmonaserrat 2 года назад +1

    Hey Ryan, great video. One question. How did you accomplish the autocomplete at 5:32, doing the auto-increment in the numbers inside the "as" prop?
    I was assuming that you selected `href="/?image=` and then did cmd+d until you had them all selected, then moved the cursor to the right and typed `as="/`, but then magic happens and you get the correct numbers.
    Thank you!

    • @RyanToronto
      @RyanToronto  2 года назад +7

      Hey Daniel, thanks! I use the vim plugin for VSCode and the way I accomplished this was using multiple cursors with the yank and put commands. Here are the exact steps:
      1) Find all of the first `href="/?image=` occurrence and hit ctrl+D to select them all.
      2) Enter vim multiple cursor mode by hitting ESC.
      3) Move the cursors over to the number. In other words I put the cursor on 4 in the `image=4` part of the href.
      4) Have each cursor copy the number it's over by using vim's yank command (the y key).
      5) Move each cursor over to and start typing the `as="/` part of the Link component.
      6) Now I use vim's put/paste command (the p key) to paste the number that was yanked by the cursor in step 4. Each cursor will paste its own number, so the line completes to `as="/{1,2,3,4,5, or 6}". Pretty amazing, It feels like magic!
      The vim plugin for VSCode blows me away every time I do something like this. There's so many cool things that fall out of knowing vim.

    • @Danicarmonaserrat
      @Danicarmonaserrat 2 года назад

      @@RyanToronto that's amazing. Thanks for the answer! I will need to check it out!

    • @seitbekir
      @seitbekir Год назад

      The easier way is just to attach cursors by pressing Alt and clicking, then move using arrows and select by Shift + ArrowRight, Ctrl+C, move to the place to write multiline code and Ctrl+V the number copied from the before.
      Is most cases the default is enough. But Vim mode is pretty good thing, yes.

  • @nonfe
    @nonfe 2 года назад

    Amazing!!!!

  • @mattl7599
    @mattl7599 Год назад

    Would this example work for Next.js 13 using the App directory without having to set the component as a client component?

    • @RyanToronto
      @RyanToronto  Год назад +1

      Hey there! I'm not sure if you can use this approach with Next 13, I haven't tried yet. That said, modals that have state would need to be client components.
      Next 13 will eventually have a better way to do modal routing with it's upcoming intercepting routes and parallel routes features. These aren't available today, but I'll make a video once they are :)

    • @kimmorvan6421
      @kimmorvan6421 Год назад +1

      I tried it out in Next.js 13 appDir but can't get it to work... If anyone has a solution i'll be happy to give it a try !

  • @Flxx57
    @Flxx57 2 года назад

    nice video

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

    But is the home page a "use client" component?

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

      Heya! This video uses the pages router, which was before server/client components existed.

  • @ЮрийВикторовичКусков

    You are cool!

  • @CodyvBrown
    @CodyvBrown 2 года назад

    Hey Ryan. this is a great tutorial and I'm trying to figure out what's not working on my implementation. how do I prevent the page from reloading when the link is clicked? that's my only issue right now but it's a big one. haha

    • @RyanToronto
      @RyanToronto  2 года назад

      Hey Cody! Double check and make sure you're using Next's Link tag around your . You'll need that to use Next's client side navigation.
      Also, you can check out the source code for the video here: github.com/ryanto/next-modal-routing.

    • @CodyvBrown
      @CodyvBrown 2 года назад

      @@RyanToronto hey ryan. I tried that and no dice but I eventually found a work around that works locally. only problem now is that when I try to deploy on Vercel I get "Type error: Binding element 'children' implicitly has an 'any' type" on the modal. any thoughts on what might be happening there?

    • @RyanToronto
      @RyanToronto  2 года назад

      @@CodyvBrown That sounds like a typescript error. You'd have to provide a type for your modal. I can't be much help there, but here's a good blog post about using typescript with react components: kentcdodds.com/blog/how-to-write-a-react-component-in-typescript

    • @CodyvBrown
      @CodyvBrown 2 года назад

      @@RyanToronto thanks! and yes. this is what was confusing me. didn't realize the file type was different on mine. am using type script. it was solved by modifying this code at the top (a friend helped): "interface Props {
      onClose: () => void;
      children: React.ReactNode;
      }
      export function Modal({ onClose = () => {}, children }: Props) {
      const overlayRef = useRef(null);
      "

    • @RyanToronto
      @RyanToronto  2 года назад

      @@CodyvBrown Awesome! Glad to hear you got it working

  • @ashwinmanghat4416
    @ashwinmanghat4416 Год назад

    Thanks 👍
    But in nextjs13 they got rid of 'as' property. Have been trying to figure out how to do this in 13

    • @iAmTheWagon
      @iAmTheWagon Год назад +1

      Same. I’ve also been trying to figure out how to do this by intercepting routes but it’s really confusing.

    • @RyanToronto
      @RyanToronto  Год назад +1

      In Next 13 you could try to combine intercepting routes with parallel routing to get a modal experience like this. I haven't done it yet so not sure I can be of much help, but if you try it let me know how it goes!

  • @ArnavSingh-im5bj
    @ArnavSingh-im5bj 2 года назад

    This does not work on sub pages. if you are on /home this will not work