Next.js Discord

Discord Forum

Best way to implement a form that spans multiple pages with the app router

Answered
Dwarf Hotot posted this in #help-forum
Open in Discord
Avatar
Dwarf HototOP
I want to create a set of pages that make a singe form flow with multiple options for a user to choose each page, with the general layout shown in the adjusted drawing.

My main question is, what would be the best / most efficient implementation for something like this, at least on the routing side.
I already know I could implement a
layout.tsx
since all pages have the exact same background. But since they also have the exact same composition, AND, I have to keep track and save in my database the options chosen, I'm not really sure how to do it.

My first thoughts were to use "catch-all" dynamic routing, but that would make all the pages accessible when they should only be one after the other in the correct order.
Example:
 mypage.com/form/question1/question2/question3/etc...


And since what actually changes in the page of each page is just two spans and a few components, maybe there is a way to implement all of this in the same page.

I'm very new to webdev and Next.js in general, so sorry if it's a dumb question.
Thanks for the help in advance.
Image
Answered by Marchy
This would probably be a good case for parallel routes
https://nextjs.org/docs/app/building-your-application/routing/parallel-routes
View full answer

2 Replies

Avatar
This would probably be a good case for parallel routes
https://nextjs.org/docs/app/building-your-application/routing/parallel-routes
Answer
Avatar
Dwarf HototOP
Checking it out, thanks a lot!