Next.js Discord

Discord Forum

Routing best practices

Answered
Brown bear posted this in #help-forum
Open in Discord
Brown bearOP
Hi!

Im working on a app, where a a user can go and create collections. Each collection contains of a set of predefined books. All these books have its own chapters and these chapters are editable and a user can take ceration actions on them.

I have a feeling that this is designed incorrect, since it's getting out of control in nested folders imo.

A chapter need to know which book it make changes to. Hence why it has been nested this way as of now.
Answered by B33fb0n3
Looks good for me. A thing, that you can do is to directly use the dynamic part. What do I mean?
Instead of heaving:
app/collections/[collectionId]/books/[bookId]/chapter/[chapterId]

You can remove the static parts of the url to:
app/[collectionId]/[bookId]/[chapterId]

Like that it's cleaner. But if you need in the future for example an overview of all collections, that would be at
app/collections/

Then your current structure is fine. So take a look in the future and think about what you are planning to do and then build your structure correctly
View full answer

4 Replies

Brown bearOP
Accicentally deleted the attachment, heres how it looks like
@Brown bear Accicentally deleted the attachment, heres how it looks like
Looks good for me. A thing, that you can do is to directly use the dynamic part. What do I mean?
Instead of heaving:
app/collections/[collectionId]/books/[bookId]/chapter/[chapterId]

You can remove the static parts of the url to:
app/[collectionId]/[bookId]/[chapterId]

Like that it's cleaner. But if you need in the future for example an overview of all collections, that would be at
app/collections/

Then your current structure is fine. So take a look in the future and think about what you are planning to do and then build your structure correctly
Answer
what above said, and also depending on how chapters are done, you could get away with just search param for it