RouteLocationOptions,
MatcherLocationRaw,
RouteParams,
+ RouteNamedLocation,
+ NamedLocationMap,
} from './types'
import { RouterHistory, HistoryState, NavigationType } from './history/common'
import {
* @param to - Route location to navigate to
*/
push(to: RouteLocationRaw): Promise<NavigationFailure | void | undefined>
+ /**
+ * Programmatically navigate to a new URL by pushing an entry in the history
+ * stack.
+ *
+ * @param to - typed route location
+ */
+ push<T extends keyof NamedLocationMap>(
+ to: RouteNamedLocation<T>
+ ): Promise<NavigationFailure | void | undefined>
+
/**
* Programmatically navigate to a new URL by replacing the current entry in
* the history stack.
import { HistoryState } from '../history/common'
import { NavigationFailure } from '../errors'
+export {
+ RouteNamedLocation,
+ NamedLocationMap,
+ defineRoutes,
+ ExtractNamedRoutes,
+} from './named'
+
export type Lazy<T> = () => Promise<T>
export type Override<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U
--- /dev/null
+import { RouteLocationOptions, RouteRecordRaw } from '.'
+
+export type ExtractNamedRoutes<
+ T extends Array<RouteRecordRaw>
+> = T extends Array<infer R>
+ ? [R] extends [{ name: string /*params?: infer Params*/ }]
+ ? {
+ [K in R['name']]: unknown /*TODO add params*/ /*R['params'] extends Params ? Params : Params*/
+ }
+ : never
+ : never
+
+// export type ExtractNamedRoutes<
+// T extends Array<RouteRecordRaw> | Readonly<Array<RouteRecordRaw>>
+// > = T extends Array<infer R>
+// ? [R] extends [{ name: string /*params?: infer Params*/ }]
+// ? {
+// [K in R['name']]: unknown /*TODO add params*/ /*R['params'] extends Params ? Params : Params*/
+// }
+// : never
+// : T extends Readonly<Array<infer R>>
+// ? [R] extends [{ name: string /*params?: infer Params*/ }]
+// ? {
+// [K in R['name']]: unknown /*TODO add params*/ /*R['params'] extends Params ? Params : Params*/
+// }
+// : never
+// : never
+
+export function defineRoutes<
+ T extends Array<RouteRecordRaw | Readonly<RouteRecordRaw>>
+>(routes: T): ExtractNamedRoutes<T> {
+ return routes as any
+}
+export interface NamedLocationMap {}
+
+export interface RouteNamedLocation<T extends keyof NamedLocationMap>
+ extends RouteLocationOptions {
+ name: T
+ params: NamedLocationMap[T]
+}
+
+declare const r: [
+ {
+ name: 'test'
+ params: {
+ number: 1
+ }
+ },
+ {
+ name: 'LOL'
+ params: {
+ sss: 'sss'
+ }
+ },
+ {
+ name: 'other'
+ },
+ {
+ path: 'ssss'
+ }
+]
+
+declare const x: ExtractNamedRoutes<typeof r>
--- /dev/null
+import { defineRoutes } from './index'
+import { DefineComponent } from 'vue'
+
+declare const Comp: DefineComponent
+
+const routes = defineRoutes([
+ {
+ path: 'my-path',
+ name: 'test',
+ component: Comp,
+ } as const,
+ {
+ path: 'my-path',
+ name: 'my-other-path',
+ component: Comp,
+ } as const,
+
+ // {
+ // path: 'my-path',
+ // component: Comp,
+ // } as const,
+])
+
+declare module './index' {
+ interface RouteMeta {
+ requiresAuth?: boolean
+ nested: { foo: string }
+ }
+}