Skip to content

tiborpino/nuxtjs-named-routes

Repository files navigation

nuxtjs-named-routes

A Nuxt.js module that sets router named routes from nuxt.config file

Features

  • Nuxt 3 support
  • Sets router named routes from nuxt.config file

Setup

  1. Add nuxtjs-named-routes dependency to your project
yarn add nuxtjs-named-routes # or npm install nuxtjs-named-routes
  1. Add nuxtjs-named-routes to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    'nuxtjs-named-routes'
  ],
  namedRoutes: {
    routes: {
        'custom-key': {
            path: '/custom-url-for-homepage',
            file: '/pages/homepage.vue'
        }
    }
  }
}
  1. 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>

Options

routes

  • Type: Object
  • Default: {}
routes: {
  'named-route-key': {
    path: '/url-path',
    file: '/pages/homepage.vue'
}
}

License

MIT License

Copyright (c) - Tibor Piňo

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published