/**
* @jest-environment jsdom
*/
-import RouterLink from '../src/components/Link'
+import { Link as RouterLink } from '../src/components/Link'
import {
START_LOCATION_NORMALIZED,
RouteQueryAndHash,
import { extractComponentsGuards } from '../src/utils'
import { START_LOCATION_NORMALIZED, RouteRecord } from '../src/types'
import { components, normalizeRouteRecord } from './utils'
-import { RouteRecordMatched } from '../src/matcher/types'
+import { RouteRecordNormalized } from '../src/matcher/types'
const beforeRouteEnter = jest.fn()
function makeAsync(
record: Exclude<RouteRecord, { redirect: any }>
-): RouteRecordMatched {
+): RouteRecordNormalized {
if ('components' in record) {
const copy = { ...record }
copy.components = Object.keys(record.components).reduce(
RouteLocationNormalized,
} from '../src/types'
import { h, resolveComponent } from 'vue'
-import { RouteRecordMatched } from '../src/matcher/types'
+import { RouteRecordNormalized } from '../src/matcher/types'
export const tick = (time?: number) =>
new Promise(resolve => {
export function normalizeRouteRecord(
// cannot be a redirect record
record: Exclude<RouteRecord, { redirect: any }>
-): RouteRecordMatched {
+): RouteRecordNormalized {
if ('components' in record)
return {
...DEFAULT_COMMON_RECORD_PROPERTIES,
}
}
-const Link = defineComponent({
+export const Link = defineComponent({
name: 'RouterLink',
props: {
to: {
return true
}
-
-export default Link
InjectionKey,
Ref,
} from 'vue'
-import { RouteRecordMatched } from '../matcher/types'
+import { RouteRecordNormalized } from '../matcher/types'
// TODO: make it work with no symbols too for IE
-export const matchedRouteKey = Symbol() as InjectionKey<Ref<RouteRecordMatched>>
+export const matchedRouteKey = Symbol() as InjectionKey<
+ Ref<RouteRecordNormalized>
+>
export const View = defineComponent({
name: 'RouterView',
leaveGuards: NavigationGuard[]
}
-// TODO: rename or refactor the duplicated type
// normalize component/components into components
export type RouteRecordNormalized = RouteRecordNormalizedCommon &
// TODO: make it required (monomorphic)
RouteRecordMultipleViews,
'path' | 'name' | 'components' | 'children' | 'meta' | 'beforeEnter'
>
-
-// When Matching a location, only RouteRecordView is possible, because redirections never end up in `matched`
-export type RouteRecordMatched = RouteRecordNormalized
import { encodeParam, decode } from './utils/encoding'
import { normalizeQuery, parseQuery, stringifyQuery } from './utils/query'
import { ref, Ref, markNonReactive, nextTick, App } from 'vue'
-import { RouteRecordMatched } from './matcher/types'
-import Link from './components/Link'
+import { RouteRecordNormalized } from './matcher/types'
+import { Link } from './components/Link'
import { View } from './components/View'
type ErrorHandler = (error: any) => any
to: RouteLocationNormalized,
from: RouteLocationNormalized
) {
- const leavingRecords: RouteRecordMatched[] = []
- const updatingRecords: RouteRecordMatched[] = []
- const enteringRecords: RouteRecordMatched[] = []
+ const leavingRecords: RouteRecordNormalized[] = []
+ const updatingRecords: RouteRecordNormalized[] = []
+ const enteringRecords: RouteRecordNormalized[] = []
// TODO: could be optimized with one single for loop
for (const record of from.matched) {
import { HistoryQuery, RawHistoryQuery } from '../utils/query'
import { PathParserOptions } from '../matcher/path-parser-ranker'
import { markNonReactive } from 'vue'
-import { RouteRecordMatched } from '../matcher/types'
+import { RouteRecordNormalized } from '../matcher/types'
// type Component = ComponentOptions<Vue> | typeof Vue | AsyncComponent
query: HistoryQuery
// TODO: do the same for params
name: string | null | undefined
- matched: RouteRecordMatched[] // non-enumerable
+ matched: RouteRecordNormalized[] // non-enumerable
redirectedFrom?: RouteLocationNormalized
meta: Record<string | number | symbol, any>
}
path: string
// record?
params: RouteLocationNormalized['params']
- matched: RouteRecordMatched[]
+ matched: RouteRecordNormalized[]
// TODO: remove optional and allow null as value (monomorphic)
redirectedFrom?: MatcherLocationNormalized
meta: RouteLocationNormalized['meta']
import { RouteLocationNormalized, RouteParams } from '../types'
import { guardToPromiseFn } from './guardToPromiseFn'
-import { RouteRecordMatched } from '../matcher/types'
+import { RouteRecordNormalized } from '../matcher/types'
export * from './guardToPromiseFn'
type GuardType = 'beforeRouteEnter' | 'beforeRouteUpdate' | 'beforeRouteLeave'
export async function extractComponentsGuards(
- matched: RouteRecordMatched[],
+ matched: RouteRecordNormalized[],
guardType: GuardType,
to: RouteLocationNormalized,
from: RouteLocationNormalized