Gabriel Uhlíř
Gabriel Uhlíř

Reputation: 639

Nuxt.js route URL without dash /

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

Upvotes: 2

Views: 319

Answers (1)

Jordan
Jordan

Reputation: 2371

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.

Upvotes: 2

Related Questions