import { router, routerHistory } from './router'
import { globalState } from './store'
import App from './App.vue'
+import { useRoute, type ParamValue, type RouteRecordInfo } from 'vue-router'
declare global {
interface Window {
app.use(router)
window.vm = app.mount('#app')
+
+export interface RouteNamedMap {
+ home: RouteRecordInfo<'home', '/', Record<never, never>, Record<never, never>>
+ '/[name]': RouteRecordInfo<
+ '/[name]',
+ '/:name',
+ { name: ParamValue<true> },
+ { name: ParamValue<false> }
+ >
+ '/[...path]': RouteRecordInfo<
+ '/[...path]',
+ '/:path(.*)',
+ { path: ParamValue<true> },
+ { path: ParamValue<false> }
+ >
+}
+
+declare module 'vue-router' {
+ interface TypesConfig {
+ RouteNamedMap: RouteNamedMap
+ }
+}
+
+const r = useRoute()
+
+if (r.name === '/[name]') {
+ r.params.name.toUpperCase()
+ // @ts-expect-error: Not existing route
+} else if (r.name === 'nope') {
+ console.log('nope')
+}
*/
import { RouterLink } from '../src/RouterLink'
import {
- START_LOCATION_NORMALIZED,
RouteQueryAndHash,
MatcherLocationRaw,
RouteLocationNormalized,
} from '../src/types'
+import { START_LOCATION_NORMALIZED } from '../src/location'
import { createMemoryHistory, RouterOptions } from '../src'
import { createMockedRoute } from './mount'
import { defineComponent, PropType } from 'vue'
*/
import { RouterView } from '../src/RouterView'
import { components, RouteLocationNormalizedLoose } from './utils'
-import {
- START_LOCATION_NORMALIZED,
- RouteLocationNormalized,
-} from '../src/types'
+import { RouteLocationNormalized } from '../src/types'
+import { START_LOCATION_NORMALIZED } from '../src/location'
import { markRaw } from 'vue'
import { createMockedRoute } from './mount'
import { mockWarn } from 'jest-mock-warn'
ErrorTypes,
} from '../src/errors'
import { components, tick } from './utils'
-import {
- RouteRecordRaw,
- NavigationGuard,
+import { RouteRecordRaw, NavigationGuard } from '../src/types'
+import type {
RouteLocationRaw,
- START_LOCATION_NORMALIZED,
RouteLocationNormalized,
-} from '../src/types'
+} from '../src/typed-routes'
import { mockWarn } from 'jest-mock-warn'
+import { START_LOCATION_NORMALIZED } from '../src/location'
const routes: Readonly<RouteRecordRaw>[] = [
{ path: '/', component: components.Home },
import { extractComponentsGuards } from '../../src/navigationGuards'
-import { START_LOCATION_NORMALIZED, RouteRecordRaw } from '../../src/types'
+import { RouteRecordRaw } from '../../src/types'
+import { START_LOCATION_NORMALIZED } from '../../src/location'
import { components } from '../utils'
import { normalizeRouteRecord } from '../../src/matcher'
import { RouteRecordNormalized } from 'src/matcher/types'
import { guardToPromiseFn } from '../../src/navigationGuards'
-import { START_LOCATION_NORMALIZED } from '../../src/types'
+import { START_LOCATION_NORMALIZED } from '../../src/location'
import { ErrorTypes } from '../../src/errors'
import { mockWarn } from 'jest-mock-warn'
import { createRouterMatcher, normalizeRouteRecord } from '../../src/matcher'
import {
- START_LOCATION_NORMALIZED,
RouteComponent,
RouteRecordRaw,
MatcherLocationRaw,
import { MatcherLocationNormalizedLoose } from '../utils'
import { mockWarn } from 'jest-mock-warn'
import { defineComponent } from '@vue/runtime-core'
+import { START_LOCATION_NORMALIZED } from '../../src/location'
const component: RouteComponent = defineComponent({})
/**
*
* @param record - Record or records we are testing the matcher against
- * @param location - location we want to reolve against
+ * @param location - location we want to resolve against
* @param [start] Optional currentLocation used when resolving
* @returns error
*/
} from '../src'
import { NavigationFailureType } from '../src/errors'
import { createDom, components, tick, nextNavigation } from './utils'
-import {
- RouteRecordRaw,
- RouteLocationRaw,
- START_LOCATION_NORMALIZED,
-} from '../src/types'
+import { RouteRecordRaw, RouteLocationRaw } from '../src/types'
import { mockWarn } from 'jest-mock-warn'
+import { START_LOCATION_NORMALIZED } from '../src/location'
declare var __DEV__: boolean
/**
- * Allows customizing existing types of the router that are used globally like `$router`, `<RouterLink>`, and `beforeRouteLeave()`. **ONLY FOR INTERNAL USAGE**.
+ * Allows customizing existing types of the router that are used globally like `$router`, `<RouterLink>`, etc. **ONLY FOR INTERNAL USAGE**.
+ *
+ * - `$router` - the router instance
+ * - `$route` - the current route location
+ * - `beforeRouteEnter` - Page component option
+ * - `beforeRouteUpdate` - Page component option
+ * - `beforeRouteLeave` - Page component option
+ * - `RouterLink` - RouterLink Component
+ * - `RouterView` - RouterView Component
*
* @internal
*/
-import {
- MatcherLocationRaw,
- MatcherLocation,
- RouteLocationRaw,
- RouteLocationNormalized,
-} from './types'
+import type { MatcherLocationRaw, MatcherLocation } from './types'
+import type { RouteLocationRaw, RouteLocationNormalized } from './typed-routes'
import { assign } from './utils'
/**
export { createRouterMatcher } from './matcher'
export type { RouterMatcher } from './matcher'
+export type * from './typed-routes'
+
export { parseQuery, stringifyQuery } from './query'
export type {
LocationQuery,
viewDepthKey,
} from './injectionSymbols'
-export { START_LOCATION_NORMALIZED as START_LOCATION } from './types'
+export { START_LOCATION_NORMALIZED as START_LOCATION } from './location'
export type {
// route location
_RouteLocationBase,
_RouteRecordBase,
RouteRecordName,
RouteRecordRaw,
- RouteRecordRedirectOption,
RouteRecordSingleView,
RouteRecordSingleViewWithChildren,
RouteRecordMultipleViews,
import type { InjectionKey, ComputedRef, Ref } from 'vue'
-import { RouteLocationNormalizedLoaded } from './types'
+import type { RouteLocationNormalizedLoaded } from './typed-routes'
import { RouteRecordNormalized } from './matcher/types'
import type { Router } from './router'
import { warn } from './warning'
import { isArray } from './utils'
import { decode } from './encoding'
+import { RouteLocationNormalizedLoaded } from './typed-routes'
/**
* Location object returned by {@link `parseURL`}.
toSegments.slice(toPosition).join('/')
)
}
+
+/**
+ * Initial route location where the router is. Can be used in navigation guards
+ * to differentiate the initial navigation.
+ *
+ * @example
+ * ```js
+ * import { START_LOCATION } from 'vue-router'
+ *
+ * router.beforeEach((to, from) => {
+ * if (from === START_LOCATION) {
+ * // initial navigation
+ * }
+ * })
+ * ```
+ */
+export const START_LOCATION_NORMALIZED: RouteLocationNormalizedLoaded = {
+ path: '/',
+ // @ts-expect-error: internal name for compatibility
+ name: undefined,
+ // TODO: could we use a symbol in the future?
+ params: {},
+ query: {},
+ hash: '',
+ fullPath: '/',
+ matched: [],
+ meta: {},
+ redirectedFrom: undefined,
+}
MatcherLocationRaw,
MatcherLocation,
isRouteName,
- RouteRecordName,
_RouteRecordProps,
+ RouteRecordName,
} from '../types'
import { createRouterError, ErrorTypes, MatcherError } from '../errors'
import { createRouteRecordMatcher, RouteRecordMatcher } from './pathMatcher'
*/
export interface RouterMatcher {
addRoute: (record: RouteRecordRaw, parent?: RouteRecordMatcher) => () => void
- removeRoute: {
- (matcher: RouteRecordMatcher): void
- (name: RouteRecordName): void
- }
+
+ removeRoute(matcher: RouteRecordMatcher): void
+ removeRoute(name: RouteRecordName): void
+
getRoutes: () => RouteRecordMatcher[]
getRecordMatcher: (name: RouteRecordName) => RouteRecordMatcher | undefined
import {
NavigationGuard,
- RouteLocationNormalized,
NavigationGuardNext,
- RouteLocationRaw,
- RouteLocationNormalizedLoaded,
NavigationGuardNextCallback,
isRouteLocation,
Lazy,
RouteComponent,
RawRouteComponent,
} from './types'
+import type {
+ RouteLocationRaw,
+ RouteLocationNormalized,
+ RouteLocationNormalizedLoaded,
+} from './typed-routes'
import {
createRouterError,
import {
- RouteLocationNormalized,
RouteRecordRaw,
- RouteLocationRaw,
NavigationHookAfter,
- START_LOCATION_NORMALIZED,
Lazy,
- RouteLocationNormalizedLoaded,
- RouteLocation,
- RouteRecordName,
isRouteLocation,
isRouteName,
NavigationGuardWithThis,
RouteLocationOptions,
MatcherLocationRaw,
- RouteParams,
} from './types'
+import type {
+ RouteLocation,
+ RouteLocationRaw,
+ RouteRecordName,
+ RouteParams,
+ RouteLocationNormalized,
+ RouteLocationNormalizedLoaded,
+} from './typed-routes'
import { RouterHistory, HistoryState, NavigationType } from './history/common'
import {
ScrollPosition,
stringifyURL,
isSameRouteLocation,
isSameRouteRecord,
+ START_LOCATION_NORMALIZED,
} from './location'
import { extractComponentsGuards, guardToPromiseFn } from './navigationGuards'
import { warn } from './warning'
routerViewLocationKey,
} from './injectionSymbols'
import { addDevtools } from './devtools'
+import { _LiteralUnion } from './types/utils'
/**
* Internal type to define an ErrorHandler
}
function resolve(
- rawLocation: Readonly<RouteLocationRaw>,
+ rawLocation: RouteLocationRaw,
currentLocation?: RouteLocationNormalizedLoaded
): RouteLocation & { href: string } {
// const objectLocation = routerLocationAsObject(rawLocation)
hash: decode(locationNormalized.hash),
redirectedFrom: undefined,
href,
- })
+ }) as any // FIXME:
}
if (__DEV__ && !isRouteLocation(rawLocation)) {
`router.resolve() was passed an invalid location. This will fail in production.\n- Location:`,
rawLocation
)
- rawLocation = {}
+ return resolve({})
}
let matcherLocation: MatcherLocationRaw
? normalizeQuery(rawLocation.query)
: ((rawLocation.query || {}) as LocationQuery),
},
- matchedRoute,
+ // make it typed
+ matchedRoute as RouteLocation,
{
redirectedFrom: undefined,
href,
if (
__DEV__ &&
- newTargetLocation.path == null &&
+ (!('path' in newTargetLocation) || newTargetLocation.path == null) &&
!('name' in newTargetLocation)
) {
warn(
--- /dev/null
+export type {
+ ParamValue,
+ ParamValueOneOrMore,
+ ParamValueZeroOrMore,
+ ParamValueZeroOrOne,
+} from './params'
+
+export type { RouteRecordInfo } from './route-map'
+
+export type {
+ _RouteRecordName as RouteRecordName,
+ _RouteLocationRaw as RouteLocationRaw,
+ _RouteLocation as RouteLocation,
+ _RouteLocationNormalized as RouteLocationNormalized,
+ _RouteLocationNormalizedLoaded as RouteLocationNormalizedLoaded,
+ _RouteLocationResolved as RouteLocationResolved,
+ _RouteLocationAsRelativePath as RouteLocationAsRelativePath,
+ _RouteParams as RouteParams,
+ _RouteParamsRaw as RouteParamsRaw,
+} from './route-location'
+
+export type { RouteRecordRedirectOption } from './route-records'
--- /dev/null
+// TODO: refactor to ParamValueRaw and ParamValue ?
+
+/**
+ * Utility type for raw and non raw params like :id+
+ *
+ */
+export type ParamValueOneOrMore<isRaw extends boolean> = [
+ ParamValue<isRaw>,
+ ...ParamValue<isRaw>[]
+]
+
+/**
+ * Utility type for raw and non raw params like :id*
+ *
+ */
+export type ParamValueZeroOrMore<isRaw extends boolean> = true extends isRaw
+ ? ParamValue<isRaw>[] | undefined | null
+ : ParamValue<isRaw>[] | undefined
+
+/**
+ * Utility type for raw and non raw params like :id?
+ *
+ */
+export type ParamValueZeroOrOne<isRaw extends boolean> = true extends isRaw
+ ? string | number | null | undefined
+ : string
+
+/**
+ * Utility type for raw and non raw params like :id
+ *
+ */
+export type ParamValue<isRaw extends boolean> = true extends isRaw
+ ? string | number
+ : string
--- /dev/null
+import type {
+ RouteLocation,
+ RouteLocationNormalized,
+ RouteLocationNormalizedLoaded,
+ RouteLocationOptions,
+ RouteQueryAndHash,
+ RouteRecordName,
+ RouteLocationRaw,
+} from '../types'
+import type { _LiteralUnion } from '../types/utils'
+// inlining the type as it avoids code splitting issues
+import type { RouteMap, _RouteMapGeneric } from './route-map'
+import type { Router } from '../router'
+
+/**
+ * Type safe version if it exists of the routes' names.
+ */
+export type _RouteRecordName = keyof RouteMap
+
+/**
+ * Type safe version of the {@link RouteLocation} type.
+ * @internal
+ */
+export interface RouteLocationTyped<
+ RouteMap extends _RouteMapGeneric,
+ Name extends keyof RouteMap
+> extends RouteLocation {
+ name: Extract<Name, RouteRecordName>
+ params: RouteMap[Name]['params']
+}
+
+/**
+ * Type safe version of the {@link RouteLocation} type as a Record with all the routes.
+ * @internal
+ */
+export type RouteLocationTypedList<
+ RouteMap extends _RouteMapGeneric = _RouteMapGeneric
+> = { [N in keyof RouteMap]: RouteLocationTyped<RouteMap, N> }
+
+/**
+ * Helper to generate a type safe version of the `RouteLocationNormalized` type.
+ * @internal
+ */
+export interface RouteLocationNormalizedTyped<
+ RouteMap extends _RouteMapGeneric = _RouteMapGeneric,
+ Name extends keyof RouteMap = keyof RouteMap
+> extends RouteLocationNormalized {
+ name: Extract<Name, RouteRecordName>
+ // we don't override path because it could contain params and in practice it's just not useful
+ params: RouteMap[Name]['params']
+}
+
+/**
+ * Helper to generate a type safe version of the `RouteLocationNormalizedLoaded` type.
+ * @internal
+ */
+export type RouteLocationNormalizedTypedList<
+ RouteMap extends _RouteMapGeneric = _RouteMapGeneric
+> = { [N in keyof RouteMap]: RouteLocationNormalizedTyped<RouteMap, N> }
+
+/**
+ * Helper to generate a type safe version of the `RouteLocationNormalizedLoaded` type.
+ * @internal
+ */
+export interface RouteLocationNormalizedLoadedTyped<
+ RouteMap extends _RouteMapGeneric = _RouteMapGeneric,
+ Name extends keyof RouteMap = keyof RouteMap
+> extends RouteLocationNormalizedLoaded {
+ name: Extract<Name, RouteRecordName>
+ // we don't override path because it could contain params and in practice it's just not useful
+ params: RouteMap[Name]['params']
+}
+
+/**
+ * Helper to generate a type safe version of the {@link RouteLocationNormalizedLoaded } type.
+ * @internal
+ */
+export type RouteLocationNormalizedLoadedTypedList<
+ RouteMap extends _RouteMapGeneric = _RouteMapGeneric
+> = { [N in keyof RouteMap]: RouteLocationNormalizedLoadedTyped<RouteMap, N> }
+
+/**
+ * Type safe adaptation of {@link LocationAsRelativeRaw}. Used to generate the union of all possible location.
+ * @internal
+ */
+export interface RouteLocationAsRelativeTyped<
+ RouteMap extends _RouteMapGeneric = _RouteMapGeneric,
+ Name extends keyof RouteMap = keyof RouteMap
+> extends RouteQueryAndHash,
+ RouteLocationOptions {
+ name?: Name
+ params?: RouteMap[Name]['paramsRaw']
+
+ // A relative path shouldn't have a path. This is easier to check with TS
+ path?: undefined
+}
+
+/**
+ * Type safe adaptation of {@link LocationAsRelativeRaw}. Used to generate the union of all possible location.
+ * @internal
+ */
+export type RouteLocationAsRelativeTypedList<
+ RouteMap extends _RouteMapGeneric = _RouteMapGeneric
+> = { [N in keyof RouteMap]: RouteLocationAsRelativeTyped<RouteMap, N> }
+
+/**
+ * Type safe version to auto complete the path of a route.
+ * @internal
+ */
+export interface RouteLocationAsPathTyped<
+ RouteMap extends _RouteMapGeneric = _RouteMapGeneric,
+ Name extends keyof RouteMap = keyof RouteMap
+> extends RouteQueryAndHash,
+ RouteLocationOptions {
+ path: _LiteralUnion<RouteMap[Name]['path']>
+
+ // // allows to check for .path and other properties that exist in different route location types
+ // [key: string]: unknown
+}
+
+/**
+ * Type safe version to auto complete the path of a route.
+ * @internal
+ */
+export type RouteLocationAsPathTypedList<
+ RouteMap extends _RouteMapGeneric = _RouteMapGeneric
+> = { [N in keyof RouteMap]: RouteLocationAsPathTyped<RouteMap, N> }
+
+/**
+ * Same as {@link RouteLocationAsPathTyped} but as a string literal.
+ * @internal
+ */
+export type RouteLocationAsString<
+ RouteMap extends _RouteMapGeneric = _RouteMapGeneric
+> = _LiteralUnion<RouteMap[keyof RouteMap]['path'], string>
+
+/**
+ * Type safe version of a resolved route location returned by `router.resolve()`.
+ * @see {@link RouteLocationTyped}
+ * @internal
+ */
+export interface RouteLocationResolvedTyped<
+ RouteMap extends _RouteMapGeneric,
+ Name extends keyof RouteMap
+> extends RouteLocationTyped<RouteMap, Name> {
+ href: string
+}
+
+/**
+ * Record of all the resolved routes.
+ * @see {@link RouteLocationResolvedTyped}
+ * @internal
+ */
+export type RouteLocationResolvedTypedList<
+ RouteMap extends _RouteMapGeneric = _RouteMapGeneric
+> = { [N in keyof RouteMap]: RouteLocationResolvedTyped<RouteMap, N> }
+
+/**
+ * Type safe versions of types that are exposed by vue-router
+ */
+
+/**
+ * Type safe version of `RouteLocationNormalized`. Accepts the name of the route as a type parameter.
+ * @see {@link RouteLocationNormalized}
+ */
+export type _RouteLocationNormalized<
+ Name extends _RouteRecordName = _RouteRecordName
+> = RouteLocationNormalizedTypedList<RouteMap>[Name]
+
+/**
+ * Type safe version of `RouteLocationNormalizedLoaded`. Accepts the name of the route as a type parameter.
+ * @see {@link RouteLocationNormalizedLoaded}
+ */
+export type _RouteLocationNormalizedLoaded<
+ Name extends _RouteRecordName = _RouteRecordName
+> = RouteLocationNormalizedLoadedTypedList<RouteMap>[Name]
+
+/**
+ * Type safe version of `RouteLocationAsRelative`. Accepts the name of the route as a type parameter.
+ * @see {@link RouteLocationAsRelative}
+ */
+export type _RouteLocationAsRelativePath<
+ Name extends _RouteRecordName = _RouteRecordName
+> = RouteLocationAsRelativeTypedList<RouteMap>[Name]
+
+/**
+ * Type safe version of `RouteLocationResolved` (the returned route of `router.resolve()`).
+ * Allows passing the name of the route to be passed as a generic.
+ * @see {@link Router['resolve']}
+ */
+export type _RouteLocationResolved<
+ Name extends keyof RouteMap = keyof RouteMap
+> = RouteLocationResolvedTypedList<RouteMap>[Name]
+
+/**
+ * Type safe version of `RouteLocation` . Allows passing the name of the route to be passed as a generic.
+ * @see {@link RouteLocation}
+ */
+export type _RouteLocation<Name extends keyof RouteMap = keyof RouteMap> =
+ RouteLocationTypedList<RouteMap>[Name]
+
+/**
+ * Type safe version of {@link `RouteLocationRaw`} . Allows passing the name of the route to be passed as a generic.
+ * @see {@link RouteLocationRaw}
+ */
+export type _RouteLocationRaw<Name extends keyof RouteMap = keyof RouteMap> =
+ | RouteLocationAsString<RouteMap>
+ | RouteLocationAsRelativeTypedList<RouteMap>[Name]
+ | RouteLocationAsPathTypedList<RouteMap>[Name]
+
+/**
+ * Generate a type safe params for a route location. Requires the name of the route to be passed as a generic.
+ * @see {@link RouteParams}
+ */
+export type _RouteParams<Name extends keyof RouteMap = keyof RouteMap> =
+ RouteMap[Name]['params']
+
+/**
+ * Generate a type safe raw params for a route location. Requires the name of the route to be passed as a generic.
+ * @see {@link RouteParamsRaw}
+ */
+export type _RouteParamsRaw<Name extends keyof RouteMap = keyof RouteMap> =
+ RouteMap[Name]['paramsRaw']
--- /dev/null
+import type { TypesConfig } from '../config'
+import type { RouteMeta, RouteParams, RouteParamsRaw } from '../types'
+import type { RouteRecord } from '../matcher/types'
+
+/**
+ * Helper type to define a Typed `RouteRecord`
+ * @see {@link RouteRecord}
+ */
+export interface RouteRecordInfo<
+ Name extends string | symbol = string,
+ Path extends string = string,
+ // TODO: could probably be inferred from the Params
+ ParamsRaw extends RouteParamsRaw = RouteParamsRaw,
+ Params extends RouteParams = RouteParams,
+ Meta extends RouteMeta = RouteMeta
+> {
+ name: Name
+ path: Path
+ paramsRaw: ParamsRaw
+ params: Params
+ // TODO: implement meta with a defineRoute macro
+ meta: Meta
+}
+
+/**
+ * Convenience type to get the typed RouteMap or a generic one if not provided.
+ */
+export type RouteMap = TypesConfig extends Record<
+ 'RouteNamedMap',
+ infer RouteNamedMap
+>
+ ? RouteNamedMap
+ : _RouteMapGeneric
+
+/**
+ * Generic version of the RouteMap.
+ * @internal
+ */
+export type _RouteMapGeneric = Record<string | symbol, RouteRecordInfo>
--- /dev/null
+import { _RouteLocation, _RouteLocationRaw } from './route-location'
+
+/**
+ * @internal
+ */
+export type RouteRecordRedirectOption =
+ | _RouteLocationRaw
+ | ((to: _RouteLocation) => _RouteLocationRaw)
import { RouteRecord, RouteRecordNormalized } from '../matcher/types'
import { HistoryState } from '../history/common'
import { NavigationFailure } from '../errors'
+import { RouteRecordRedirectOption } from '../typed-routes'
export type Lazy<T> = () => Promise<T>
export type Override<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U
*/
export interface RouteMeta extends Record<string | number | symbol, unknown> {}
-/**
- * @internal
- */
-export type RouteRecordRedirectOption =
- | RouteLocationRaw
- | ((to: RouteLocation) => RouteLocationRaw)
-
/**
* Route Record defining one single component with the `component` option.
*/
| RouteRecordMultipleViewsWithChildren
| RouteRecordRedirect
-/**
- * Initial route location where the router is. Can be used in navigation guards
- * to differentiate the initial navigation.
- *
- * @example
- * ```js
- * import { START_LOCATION } from 'vue-router'
- *
- * router.beforeEach((to, from) => {
- * if (from === START_LOCATION) {
- * // initial navigation
- * }
- * })
- * ```
- */
-export const START_LOCATION_NORMALIZED: RouteLocationNormalizedLoaded = {
- path: '/',
- name: undefined,
- params: {},
- query: {},
- hash: '',
- fullPath: '/',
- matched: [],
- meta: {},
- redirectedFrom: undefined,
-}
-
// make matched non-enumerable for easy printing
// NOTE: commented for tests at RouterView.spec
// Object.defineProperty(START_LOCATION_NORMALIZED, 'matched', {
-import { RouteLocationRaw, RouteRecordName } from './index'
+import { RouteLocationRaw, RouteRecordName } from '../typed-routes'
export function isRouteLocation(route: any): route is RouteLocationRaw {
return typeof route === 'string' || (route && typeof route === 'object')
}
-export function isRouteName(name: any): name is RouteRecordName {
+export function isRouteName(name: any): name is string | symbol {
return typeof name === 'string' || typeof name === 'symbol'
}
/**
+ * Creates a union type that still allows autocompletion for strings.
* @internal
*/
export type _LiteralUnion<LiteralType, BaseType extends string = string> =
| LiteralType
| (BaseType & Record<never, never>)
+/**
+ * Maybe a promise maybe not
+ * @internal
+ */
+export type _Awaitable<T> = T | PromiseLike<T>
+
/**
* @internal
*/
import { inject } from 'vue'
import { routerKey, routeLocationKey } from './injectionSymbols'
import { Router } from './router'
-import { RouteLocationNormalizedLoaded } from './types'
+import { RouteMap } from './typed-routes/route-map'
+import { RouteLocationNormalized } from './typed-routes'
/**
* Returns the router instance. Equivalent to using `$router` inside
* Returns the current route location. Equivalent to using `$route` inside
* templates.
*/
-export function useRoute(): RouteLocationNormalizedLoaded {
+export function useRoute<Name extends keyof RouteMap = keyof RouteMap>(
+ _name?: Name
+): RouteLocationNormalized<Name> {
return inject(routeLocationKey)!
}