Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

nuxt-route-meta

dword-design8.1kMIT5.0.3

Adds Nuxt page data to route meta at build time. Also supports TypeScript.

auth, authentication, frontend, javascript, meta-data, node, nodejs, npm, npm-package, nuxt, nuxt-module, nuxtjs, nuxtjs-module, page, pages, route, router, vue, vue-router, webdevelopment

readme

nuxt-route-meta

npm version Linux macOS Windows compatible Build status Coverage status Dependency status Renovate enabled
Open in Gitpod Buy Me a Coffee PayPal Patreon

Adds Nuxt page data to route meta at build time. Also supports TypeScript.

Nuxt pages have a meta property that allows to define meta data. These can be accessed in middlewares via route.meta at runtime. What does not work however is to access the meta data at build time in the routes object itself. This is needed when postprocessing routes via extendRoutes (Nuxt 2), pages:extend (Nuxt 3), extendPages or the @nuxtjs/sitemap module. This module fills this gap by parsing the page files, extracting the meta data, and writing them to the meta field of each route corresponding to the page.

ℹ️ Note that this module can only extract static data from the pages at build time. It will not work with dynamic data depending on this. In case you have an idea how to improve that, feel free to open up an issue or pull request.

Install

# npm
$ npx nuxi module add nuxt-route-meta

# Yarn
$ yarn nuxi module add nuxt-route-meta

Usage

Add the module to your nuxt.config.js:

export default {
  modules: [
    'nuxt-route-meta',
  ]
}

Add some properties to your pages:

<template>
  <div>Hello world</div>
</template>
<script>
export default {
  auth: true,
  meta: {
    theme: 'water',
  },
}
</script>

That's it! Now you can access the meta data in route.meta from anywhere as you know it from vue-router. The module takes all properties that all properties that are not functions, and the meta property itself is merged into the result. So route.meta from the example above is { auth: true, theme: 'water' }.

Here is an example to use it inside nuxt.hook('pages:extend') in a module:

export default defineNuxtModule((options, nuxt) =>
  nuxt.hook('pages:extend', routes =>
    for (const route of routes) {
      if (route.meta.auth) {
        // do something with auth routes
      }
    }
  )
)

Composition API

<script setup>
definePageMeta({
  auth: true,
})
</script>

TypeScript

The module has built-in support for TypeScript.

<script lang="ts">
export default defineComponent({
  auth: true,
  meta: {
    theme: 'water',
  },
})
</script>

Contribute

Are you missing something or want to contribute? Feel free to file an issue or a pull request! ⚙️

Support

Hey, I am Sebastian Landwehr, a freelance web developer, and I love developing web apps and open source packages. If you want to support me so that I can keep packages up to date and build more helpful tools, you can donate here:

Buy Me a Coffee  If you want to send me a one time donation. The coffee is pretty good 😊.
PayPal  Also for one time donations if you like PayPal.
Patreon  Here you can support me regularly, which is great so I can steadily work on projects.

Thanks a lot for your support! ❤️

See also

  • nuxt-mail: Adds email sending capability to a Nuxt.js app. Adds a server route, an injected variable, and uses nodemailer to send emails.
  • nuxt-modernizr: Adds a Modernizr build to your Nuxt.js app.
  • nuxt-mermaid-string: Embed a Mermaid diagram in a Nuxt.js app by providing its diagram string.
  • nuxt-content-git: Additional module for @nuxt/content that replaces or adds createdAt and updatedAt dates based on the git history.
  • nuxt-babel-runtime: Nuxt CLI that supports babel. Inspired by @nuxt/typescript-runtime.

License

MIT License © Sebastian Landwehr

changelog

5.0.3 (2024-06-15)

Bug Fixes

5.0.2 (2024-06-15)

Bug Fixes

5.0.1 (2024-04-08)

Bug Fixes

5.0.0 (2024-02-12)

Bug Fixes

BREAKING CHANGES

  • require node.js >= 18

4.0.0 (2023-07-02)

Bug Fixes

BREAKING CHANGES

  • drop node 14, migrate to nuxt 3

3.0.10 (2023-04-30)

Bug Fixes

3.0.9 (2023-04-30)

Bug Fixes

3.0.8 (2023-04-30)

Bug Fixes

3.0.7 (2023-04-20)

Bug Fixes

  • update dependency output-files to v2.0.27 (4472461)
  • update dependency ts-ast-to-literal to v3.0.12 (42ec55e)

3.0.6 (2023-04-19)

Bug Fixes

  • update dependency @dword-design/functions to v4.1.7 (846704e)

3.0.5 (2023-04-19)

Bug Fixes

3.0.4 (2023-03-16)

Bug Fixes

  • update dependency output-files to v2.0.13 (da201f2)

3.0.3 (2023-03-16)

Bug Fixes

  • update dependency @babel/traverse to v7.21.3 (fe1ab32)
  • update dependency output-files to v2.0.12 (aa57262)

3.0.2 (2023-03-15)

Bug Fixes

  • update dependency @babel/core to v7.21.3 (eea4f1a)

3.0.1 (2023-02-15)

Bug Fixes

3.0.0 (2022-12-05)

Bug Fixes

BREAKING CHANGES

  • drop node 12 support, move to esm

2.3.6 (2022-10-13)

Bug Fixes

2.3.5 (2022-07-25)

Bug Fixes

2.3.4 (2022-01-06)

Bug Fixes

2.3.3 (2022-01-04)

Bug Fixes

2.3.2 (2021-09-02)

Bug Fixes

2.3.1 (2021-09-02)

Bug Fixes

2.3.0 (2021-09-02)

Bug Fixes

Features

2.2.2 (2021-08-23)

Bug Fixes

  • typescript class api support (fc17626)

2.2.1 (2021-08-19)

Bug Fixes

  • document typescript (596c600)
  • update config files (a74fa66)
  • write GitHub metadata to package.json [description] (#62) (c474e05)

2.2.0 (2021-08-19)

Features

2.1.4 (2021-08-12)

Bug Fixes

  • omit predefined vue properties (e1943ef)

2.1.3 (2021-07-20)

Bug Fixes

2.1.2 (2021-07-06)

Bug Fixes

2.1.1 (2021-06-29)

Bug Fixes

2.1.0 (2021-06-26)

Features

2.0.7 (2021-06-16)

Bug Fixes

  • use official ast-to-literal (7ba5fd1)

2.0.6 (2021-06-14)

Bug Fixes

2.0.5 (2021-05-28)

Bug Fixes

2.0.4 (2021-05-15)

Bug Fixes

2.0.3 (2021-05-04)

Bug Fixes

2.0.2 (2021-05-04)

Bug Fixes

  • update dependency @dword-design/functions to v4 (#36) (94c8d1c)
  • update dependency depcheck-package-name to v2 (#37) (a731ee0)
  • update dependency output-files to v2 (#38) (b91912f)

2.0.1 (2021-05-04)

Bug Fixes

  • update dependency fs-extra to v10 (#39) (e86ff68)
  • update dependency with-local-tmp-dir to v4 (#40) (0961603)

2.0.0 (2021-05-03)

Bug Fixes

  • update dependency @dword-design/base to v8 (#35) (2ce3ae1)

BREAKING CHANGES

  • require Node.js >= 12

Co-authored-by: Renovate Bot bot@renovateapp.com Co-authored-by: Sebastian Landwehr info@dword-design.de Co-authored-by: GitHub Actions actions@github.com

1.0.16 (2021-04-26)

Bug Fixes

  • update dependency with-local-tmp-dir to v3 (#32) (01e28f3)

1.0.15 (2021-04-20)

Bug Fixes

1.0.14 (2021-04-12)

Bug Fixes

1.0.13 (2021-04-09)

Bug Fixes

1.0.12 (2021-04-05)

Bug Fixes

1.0.11 (2021-04-05)

Bug Fixes

  • add array and nested object support. also removed additionalProperties config (#21) (ff79e8f)

1.0.10 (2021-03-23)

Bug Fixes

  • update dependency @dword-design/functions to v3 (#15) (cbda3cb)

1.0.9 (2021-03-22)

Bug Fixes

1.0.8 (2021-03-18)

Bug Fixes

1.0.7 (2021-03-17)

Bug Fixes

1.0.6 (2021-03-11)

Bug Fixes

1.0.5 (2021-03-09)

Bug Fixes

1.0.4 (2021-02-17)

Bug Fixes

1.0.3 (2020-12-12)

Bug Fixes

  • further explain purpose of this module in readme (89f25db)

1.0.2 (2020-12-02)

Bug Fixes

  • config: Update changed files (2753fce)

1.0.1 (2020-08-25)

Bug Fixes

  • config: Update changed files (332e7cc)

1.0.0 (2020-08-19)

Features