It seems to still have value as it work in app code...
// route records
RouteRecordInfo,
+ RouteRecordNameGeneric,
RouteRecordName,
_RouteRecordProps,
RouteRecordRedirectOption,
import { warn } from '../warning'
import { assign, noop } from '../utils'
-import type { RouteRecordName, _RouteRecordProps } from '../typed-routes'
+import type { RouteRecordNameGeneric, _RouteRecordProps } from '../typed-routes'
/**
* Internal RouterMatcher
addRoute: (record: RouteRecordRaw, parent?: RouteRecordMatcher) => () => void
removeRoute(matcher: RouteRecordMatcher): void
- removeRoute(name: NonNullable<RouteRecordName>): void
+ removeRoute(name: NonNullable<RouteRecordNameGeneric>): void
getRoutes: () => RouteRecordMatcher[]
getRecordMatcher: (
- name: NonNullable<RouteRecordName>
+ name: NonNullable<RouteRecordNameGeneric>
) => RouteRecordMatcher | undefined
/**
): RouterMatcher {
// normalized ordered array of matchers
const matchers: RouteRecordMatcher[] = []
- const matcherMap = new Map<RouteRecordName, RouteRecordMatcher>()
+ const matcherMap = new Map<
+ NonNullable<RouteRecordNameGeneric>,
+ RouteRecordMatcher
+ >()
globalOptions = mergeOptions(
{ strict: false, end: true, sensitive: false } as PathParserOptions,
globalOptions
)
- function getRecordMatcher(name: RouteRecordName) {
+ function getRecordMatcher(name: NonNullable<RouteRecordNameGeneric>) {
return matcherMap.get(name)
}
}
function removeRoute(
- matcherRef: NonNullable<RouteRecordName> | RouteRecordMatcher
+ matcherRef: NonNullable<RouteRecordNameGeneric> | RouteRecordMatcher
) {
if (isRouteName(matcherRef)) {
const matcher = matcherMap.get(matcherRef)
RouteLocationAsRelative,
RouteLocationAsPath,
RouteLocationAsString,
- RouteRecordName,
+ RouteRecordNameGeneric,
} from './typed-routes'
import { RouterHistory, HistoryState, NavigationType } from './history/common'
import {
* @param route - Route Record to add
*/
addRoute(
- // NOTE: RouteRecordName could be `keyof RouteMap` but the point of dynamic routes is not knowing the routes at build
- parentName: NonNullable<RouteRecordName>,
+ // NOTE: it could be `keyof RouteMap` but the point of dynamic routes is not knowing the routes at build
+ parentName: NonNullable<RouteRecordNameGeneric>,
route: RouteRecordRaw
): () => void
/**
*
* @param name - Name of the route to remove
*/
- removeRoute(name: NonNullable<RouteRecordName>): void
+ removeRoute(name: NonNullable<RouteRecordNameGeneric>): void
/**
* Checks if a route with a given name exists
*
* @param name - Name of the route to check
*/
- hasRoute(name: NonNullable<RouteRecordName>): boolean
+ hasRoute(name: NonNullable<RouteRecordNameGeneric>): boolean
/**
* Get a full list of all the {@link RouteRecord | route records}.
*/
applyToParams.bind(null, decode)
function addRoute(
- parentOrRoute: NonNullable<RouteRecordName> | RouteRecordRaw,
+ parentOrRoute: NonNullable<RouteRecordNameGeneric> | RouteRecordRaw,
route?: RouteRecordRaw
) {
let parent: Parameters<(typeof matcher)['addRoute']>[1] | undefined
return matcher.addRoute(record, parent)
}
- function removeRoute(name: NonNullable<RouteRecordName>) {
+ function removeRoute(name: NonNullable<RouteRecordNameGeneric>) {
const recordMatcher = matcher.getRecordMatcher(name)
if (recordMatcher) {
matcher.removeRoute(recordMatcher)
return matcher.getRoutes().map(routeMatcher => routeMatcher.record)
}
- function hasRoute(name: NonNullable<RouteRecordName>): boolean {
+ function hasRoute(name: NonNullable<RouteRecordNameGeneric>): boolean {
return !!matcher.getRecordMatcher(name)
}
import type { RouteMap, RouteMapGeneric } from './route-map'
import type { Router } from '../router'
import type { RouteRecord, RouteRecordNormalized } from '../matcher/types'
-import type { RouteRecordName } from './route-records'
+import type { RouteRecordNameGeneric } from './route-records'
/**
* Generic version of {@link RouteLocation}. It is used when no {@link RouteMap} is provided.
* Generic version of {@link RouteLocationNormalized} that is used when no {@link RouteMap} is provided.
*/
export interface RouteLocationNormalizedGeneric extends _RouteLocationBase {
- name: RouteRecordName
+ name: RouteRecordNameGeneric
params: RouteParamsGeneric
/**
* Array of {@link RouteRecordNormalized}
export interface RouteLocationAsRelativeGeneric
extends RouteQueryAndHash,
RouteLocationOptions {
- name?: RouteRecordName
+ name?: RouteRecordNameGeneric
params?: RouteParamsRawGeneric
/**
* A relative path to the current location. This property should be removed
RouteLocationNormalized,
RouteLocationRaw,
} from './route-location'
-import type { RouteMap } from './route-map'
+import type { RouteMap, RouteMapGeneric } from './route-map'
/**
* @internal
| RouteLocationRaw
| ((to: RouteLocation) => RouteLocationRaw)
+/**
+ * Generic version of {@link RouteRecordName}.
+ */
+export type RouteRecordNameGeneric = string | symbol | undefined
+
/**
* Possible values for a route record **after normalization**
*
- * NOTE: since `RouteRecordName` is a type, it evaluates too early and it's always be a generic version. If you need a typed version of all of the names of routes, use {@link RouteMap | `keyof RouteMap`}
+ * NOTE: since `RouteRecordName` is a type, it evaluates too early and it's often the generic version {@link RouteRecordNameGeneric}. If you need a typed version of all of the names of routes, use {@link RouteMap | `keyof RouteMap`}
*/
-export type RouteRecordName = string | symbol | undefined
+export type RouteRecordName = RouteMapGeneric extends RouteMap
+ ? RouteRecordNameGeneric
+ : keyof RouteMap
/**
* @internal
RouteLocation,
RouteRecordRedirectOption,
_RouteRecordProps,
- RouteRecordName,
+ RouteRecordNameGeneric,
} from '../typed-routes'
import type { _Awaitable } from './utils'
* @internal
*/
export interface MatcherLocationAsName {
- name: RouteRecordName
+ name: RouteRecordNameGeneric
// to allow checking location.path == null
/**
* Ignored path property since we are dealing with a relative location. Only `undefined` is allowed.
* @internal
*/
export interface LocationAsRelativeRaw {
- name?: RouteRecordName
+ name?: RouteRecordNameGeneric
// to allow checking location.path == null
/**
* Ignored path property since we are dealing with a relative location. Only `undefined` is allowed.
/**
* Name for the route record. Must be unique.
*/
- name?: RouteRecordName
+ name?: RouteRecordNameGeneric
/**
* Before Enter guard specific to this record. Note `beforeEnter` has no
/**
* Name of the matched record
*/
- name: RouteRecordName | null | undefined
+ name: RouteRecordNameGeneric | null | undefined
/**
* Percentage encoded pathname section of the URL.
-import type { RouteLocationRaw, RouteRecordName } from '../typed-routes'
+import type { RouteLocationRaw, RouteRecordNameGeneric } 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 RouteRecordNameGeneric {
return typeof name === 'string' || typeof name === 'symbol'
}