Дмитрий BiM
Дмитрий BiM

Reputation: 11

Static and dynamic routes on the same level with Nuxt.js

I'm trying to set up routing on a site (Nuxt.js) Using @nuxtjs/router to create my own router.js file. Faced the problem of locating dynamic and static routes on the same level. I have the structure like this:

/:slug
/contacts

Opening /contacts get the wrong page with slug "contacts"

To change the structure e.g./hotels/:slug is not the way out for my situation. So.. how can i do this? Is there a way to set the priority of routes. Digging in the direction of extendRoutes did not bring any results.

Upvotes: 1

Views: 1640

Answers (2)

Amir Afshar
Amir Afshar

Reputation: 11

You should put your static pages inside their own folder with their own index.vue
example:

_slug
    index.vue
features
    index.vue
contacts
    index.vue

Upvotes: 1

Mani Mirjavadi
Mani Mirjavadi

Reputation: 1073

Try this: create a folder named contacts a file inside the folder named index.vue. Now create another file named _slug.vue in the same level as the index.vue.

It will be something like this:

--contacts
|--- _slug.vue
|--- index.vue

Now the route /contacts/ will open the index.vue and contacts/something opens up _slug.vue with something as a slug.

Upvotes: 2

Related Questions