Skip to content
Advertisement

Catch all routes in NuxtJS pages routing

I have this page route in NuxtJS:

pages/_book.vue

So that when I go to localhost:3000/my-book, params.book is equal to “my-book” as expected.

However some books are nested deep inside several directories. I want to get the full route as params.book. These routes should be separated by “/”. For example, localhost:3000/finance/strategies/experts should make params.book equal to “finance/strategies/experts”.

How can I achieve this?

Note that since the directory structure is unknown (i.e. I can’t just create a structure like pages/_book/_type/_level.vue)

Advertisement

Answer

You can use Unknown Dynamic Nested Routes to match routes that are not caught by other patterns.

With this file tree:

JavaScript

It will behave like this

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement