A Nuxt.js module that sets router named routes from nuxt.config file
- Nuxt 3 support
- Sets router named routes from nuxt.config file
- Add
nuxtjs-named-routes
dependency to your project
yarn add nuxtjs-named-routes # or npm install nuxtjs-named-routes
- Add
nuxtjs-named-routes
to themodules
section ofnuxt.config.ts
export default defineNuxtConfig({
modules: [
'nuxtjs-named-routes'
],
namedRoutes: {
routes: {
'custom-key': {
path: '/custom-url-for-homepage',
file: '/pages/homepage.vue'
}
}
}
}
- Use the named route
<NuxtLink :to="{name: 'custom-key'}">Link to the homepage</NuxtLink>
The code above will generate HTML link
<a href="/custom-url-for-homepage">Link to the homepage</a>
- Type:
Object
- Default:
{}
routes: {
'named-route-key': {
path: '/url-path',
file: '/pages/homepage.vue'
}
}
Copyright (c) - Tibor Piňo