Routing | nuxt router param
Nuxt.jsautomaticallygeneratesthevue-router[1]configurationbasedonyourfiletreeofVuefilesinsidethepagesdirectory.Tonavigatebetweenpages,werecommendtousethe
Nuxt.js automatically generates the vue-router[1] configuration based on your file tree of Vue files inside the pages directory.
To navigate between pages, we recommend to use the <nuxt-link>[2] component.
For example:
<template> <nuxt-link to="/">Home page</nuxt-link> </template>Basic RoutesThis file tree:
pages/ --| user/ -----| index.vue -----| one.vue --| index.vuewill automatically generate:
router: { routes: [ { name: index, path: /, component: pages/index.vue }, { name: user, path: /user, component: pages/user/index.vue }, { name: user-one, path: /user/one, component: pages/user/one.vue } ] }Dynamic RoutesTo define a dynamic route with a parameter, you need to define a .vue file OR a directory prefixed by an underscore.
This file tree:
pages/ --| _slug/ -----| comments.vue -----| index.vue --| users/ -----| _id...