/**
* Merged `meta` properties from all of the matched route records.
*/
- meta: Record<string | number | symbol, any>
+ meta: RouteMeta
}
// matched contains resolved components
/**
* Arbitrary data attached to the record.
*/
- meta?: Record<string | number | symbol, any>
+ meta?: RouteMeta
}
+export interface RouteMeta extends Record<string | number | symbol, any> {}
+
export type RouteRecordRedirectOption =
| RouteLocationRaw
| ((to: RouteLocation) => RouteLocationRaw)
--- /dev/null
+import { createRouter, createWebHistory, expectType } from './index'
+import { createApp, defineComponent } from 'vue'
+
+const component = defineComponent({})
+
+declare module './index' {
+ interface RouteMeta {
+ requiresAuth?: boolean
+ nested: { foo: string }
+ }
+}
+
+const router = createRouter({
+ history: createWebHistory(),
+ routes: [
+ {
+ path: '/',
+ component,
+ meta: {
+ requiresAuth: true,
+ lol: true,
+ nested: {
+ foo: 'bar',
+ },
+ },
+ },
+ {
+ path: '/foo',
+ // @ts-ignore
+ component,
+ // @ts-expect-error
+ meta: {},
+ },
+ ],
+})
+
+router.beforeEach(to => {
+ expectType<{ requiresAuth?: Boolean; nested: { foo: string } }>(to.meta)
+ if (to.meta.nested.foo == 'foo' || to.meta.lol) return false
+})
+
+const app = createApp({})
+app.use(router)