0

Hello everyone I have a problem regarding nextJS routing i have the following folder structure and its works fine for a simple scenario where a project has only one folder and this folder have one domain but my problem occurs when a project has a folder and this folder have many subfolders

for example if i have this URL projects/1/folder1/subfolder1/subsubfolder1/.../domain1

so as you can see i don't know how many slugs i will have how can I achieve this??

Ali Berro
  • 11
  • 1
  • 2

1 Answers1

6

Dynamic routes can be extended to catch all paths by adding three dots (...) inside the brackets.

It means you can create a file with name [...folder].js and in that file, you can write your logic to handle the route.

You can even make it optional by including the parameter in double brackets ([[...folder]]). This allows /base, /base/a, /base/a/b, and so on.

To access folder object you can simply get it from query as

{ "folder": ["a", "b"] }
puncoz
  • 497
  • 2
  • 9