'NuxtJs dynamic routing

In NuxtJS (vuejs framework), I am having some difficulty with routes, I wanted to ask how we can create this kind of route using pages directory or any other approach?

Example:

Sample routes:

/some-route-of-page-2021

/some-route-of-page-2022 and so on for every year.

2021/2021 is the year and that will be dynamic



Solution 1:[1]

Having a dynamic variable inside of a path itself is supported in Nuxt3 . In Nuxt2, you can only have /some-route-of-page/XXX. In this case, it seems a bit more logical to have this kind of structure anyway. Usually, you don't have a lot of variables interpolated in the path itself, can be kinda confusing IMO.

Solution 2:[2]

Dynamic Pages are handled by adding an underscore in front of the parameter. For example "_pageyear.vue"

Docs: https://nuxtjs.org/examples/routing/dynamic-pages/ Sandbox: https://codesandbox.io/s/github/nuxtlabs/examples/tree/master/routing/dynamic-pages?from-embed

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kissu
Solution 2 James_jpst