Nuxt.js: meta is not available in $route

Created on 10 Jan 2018  路  13Comments  路  Source: nuxt/nuxt.js

I've noticed that the new meta object is only injected into context, but is not available on a page through this.$route.meta

Is there a reason why it is not possible to update the routers meta object or is there an other method I can get access to the meta information without using a middleware?
Thank you.

This question is available on Nuxt.js community (#c2217)

Most helpful comment

Any update on this? Seems like this.$route.meta is always empty even when I put data in the meta property of the page...

All 13 comments

this.$route.meta is not a vue-meta object, it's defined by vue-route meta.

If you want to access context.meta, you can access it in asyncData inside the component or combine meta with data or state, maybe sth like https://github.com/nuxt/nuxt.js/issues/2536#issuecomment-356259396.

I'm not sure I understand this correctly.
I know that this.$route.meta is not a vue-meta object, it should be the vue-route meta.
In 1.0 the new feature was introduced where you ca define the meta object from inside a page: https://github.com/nuxt/nuxt.js/issues/1687#issuecomment-331870619

But as far as I can see this new meta object is only available where context is available. So in middleware, asyncData... But if I have a component (not page component) I have no access to this meta object since it is not available on this.$route.meta and I can't get context.

I think you can store the meta info into the store.state, then it can be shared among the components.

Yes, but I would have to do it on every page I use the component, and have additional data in the store that is only used in one component.
I think it would be more convenient and consistent if this.$route.meta is updated.

So if there is no technical reason why this hasn't been done, I will look into it and submit a PR if I can find a good solution.

Sure, we always welcome any positive contribution, thanks 馃樃

Was just looking for a way to set/get route meta properties. So I'll +1 this

just linking to a similar ticket https://github.com/nuxt/nuxt.js/issues/466

Any update on this? Seems like this.$route.meta is always empty even when I put data in the meta property of the page...

Yes, being able to set up the route.meta would great. I could define access levels and a automatic breadcrumb creation with this.

While searching for how to override the nuxt router, I found this medium article: https://medium.com/@francesco.greppi/custom-routes-with-nuxt-js-5b87036fd389

modules is the answer. I might try experimenting with it so I don't have to override all the routes but instead just map and add meta.

EDIT
Apparently, mapping routes router.extendRoutes inside nuxt.config.js and adding meta object works fine.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Fixed in #4478

Was this page helpful?
0 / 5 - 0 ratings

Related issues

msudgh picture msudgh  路  3Comments

vadimsg picture vadimsg  路  3Comments

bimohxh picture bimohxh  路  3Comments

pehbehbeh picture pehbehbeh  路  3Comments

bimohxh picture bimohxh  路  3Comments