unplugin-vue-router
unplugin-vue-router copied to clipboard
implement nuxt's definePageMeta
In Nuxt, we extract route metadata through a macro and need to inject this in the generated routes. We don't serialise it but instead keep it in the rollup build and import with a custom query param, e.g. import { meta } from '~/pages/index.vue?macro=true
.
Using a library like this, we would either need to take full control of the generated routes file (not the .d.ts
) or have a callback to manipulate the generated file, ideally via some kind of AST that lets us have raw access to inject real code.
Edit by Eduardo: after calling with Daniel, we should add the same macro Nuxt has (definePageMeta()
) See if we should name it differently and allow rename through option.
Hi,
I have done some tests with many pages and with the current implementation (i.e. with a route block to configure meta data). Currently it doesn't matter if there are two pages or a thousand pages, it's always super fast. With Nuxt and definePageMeta(), loading an app with a thousand pages takes some time (5 seconds in my case) because all pages are called with ?macro=true.
For this reason I would prefer some kind of configuration to disable the definePageMeta() behavior. Or will this implementation be different from the Nuxt implementation? Or is there a way to optimize this that I am not aware of?
Added definePage()
to the docs and released it. I think the version tries to skip parsing as soon as possible but ideally there should be hooks in vue compiler (https://github.com/vuejs/rfcs/discussions/430) to make this faster
This was implemented a long time ago with definePage()
, I don't think it's necessary to add an extra macro at the moment