Home > OS >  Nuxt JS dynamic param on nested page
Nuxt JS dynamic param on nested page

Time:05-28

I'm trying to create a dynamic param for one of my nuxt JS pages and am struggling to figure out the correct folder structure, the URL I need will be something like:

Where 123 is my dynamic param that I need to grab using this.$route.

I've tried the following folder markups:

  • pages/_landing/index.vue
  • pages/landing/_index.vue

How can I achieve this?

I still need the page to load even if my param isn't supplied

CodePudding user response:

use the [ ] syntax

pages/landing/[paramName].vue

further read https://v3.nuxtjs.org/guide/directory-structure/pages#dynamic-routes

CodePudding user response:

If 123 is the id, you need to save the file as _id.vue then you can get the value of id using this.$route.params.id

Edit: You directory structure will be pages/landing/_id.vue

  • Related