Nuxt.js route URL without dash /

Viewed 115

Is it possible to remove folder dash from URL?

From: url.com/p/123456 and url.com/t/123456

To: url.com/p123456 and url.com/t123456


Folder structure:

/pages
|—/p
|—|—_id.vue
|—/t
|—|—_id.vue
p.vue
t.vue
1 Answers

Any time you put a file inside a folder in the pages folder, it'll generate that /folderName/ structure because that is its intended behaviour.

To achieve what you want, you simply have to create a slug at the bottom level:

/pages
|-_id.vue
p.vue
t.vue

From this page, you can access the slug parameter as you would normally.

If you need to distinguish between what was /p and what was /t files, you can create a computed function that checks a substring of the current route and then reacts accordingly.

Related