import { extractComponentsGuards } from '../src/utils'
import { START_LOCATION_NORMALIZED, RouteRecord } from '../src/types'
-import { components, normalizeRouteRecord } from './utils'
+import { components } from './utils'
import { RouteRecordNormalized } from '../src/matcher/types'
+import { normalizeRouteRecord } from '../src/matcher'
const beforeRouteEnter = jest.fn()
children: undefined,
components: { default: {} },
leaveGuards: [],
- meta: undefined,
+ meta: {},
name: undefined,
path: '/home',
})
children: undefined,
components: {},
leaveGuards: [],
- meta: undefined,
+ meta: {},
name: undefined,
path: '/redirect',
})
-import { createRouterMatcher } from '../../src/matcher'
+import { createRouterMatcher, normalizeRouteRecord } from '../../src/matcher'
import {
START_LOCATION_NORMALIZED,
RouteComponent,
MatcherLocationNormalized,
MatcherLocationRedirect,
} from '../../src/types'
-import { normalizeRouteRecord, MatcherLocationNormalizedLoose } from '../utils'
+import { MatcherLocationNormalizedLoose } from '../utils'
// @ts-ignore
const component: RouteComponent = null
resolved.meta = record[0].meta || {}
}
+ if (!('name' in resolved)) {
+ resolved.name = undefined
+ }
+
// add location if provided as it should be the same value
if ('path' in location && !('path' in resolved)) {
resolved.path = location.path
import { JSDOM, ConstructorOptions } from 'jsdom'
import {
NavigationGuard,
- RouteRecord,
RouteRecordMultipleViews,
MatcherLocationNormalized,
RouteLocationNormalized,
} from '../src/types'
import { h, resolveComponent } from 'vue'
-import { RouteRecordNormalized } from '../src/matcher/types'
export const tick = (time?: number) =>
new Promise(resolve => {
},
},
}
-
-const DEFAULT_COMMON_RECORD_PROPERTIES = {
- beforeEnter: undefined,
- leaveGuards: [],
- meta: undefined,
-}
-
-/**
- * Adds missing properties
- *
- * @param record
- * @returns a normalized copy
- */
-export function normalizeRouteRecord(
- // cannot be a redirect record
- record: Exclude<RouteRecord, { redirect: any }>
-): RouteRecordNormalized {
- if ('components' in record)
- return {
- ...DEFAULT_COMMON_RECORD_PROPERTIES,
- ...record,
- }
-
- const { component, ...rest } = record
-
- return {
- ...DEFAULT_COMMON_RECORD_PROPERTIES,
- ...rest,
- components: { default: component },
- }
-}
}),
alias({
resolve: ['ts'],
- consola: path.resolve(__dirname, './src/consola.ts'),
}),
],
output: {
path,
params,
matched,
- // TODO: merge all meta properties from parent to child
- meta: (matcher && matcher.record.meta) || {},
+ meta: matcher ? matcher.record.meta : {},
}
}
children: (record as any).children,
name: record.name,
beforeEnter,
- meta: record.meta,
+ meta: record.meta || {},
leaveGuards: [],
}
}
import { RouteRecordMultipleViews, NavigationGuard } from '../types'
-export interface RouteRecordNormalizedCommon {
+// normalize component/components into components and make every property always present
+export interface RouteRecordNormalized {
+ path: RouteRecordMultipleViews['path']
+ name: RouteRecordMultipleViews['name']
+ components: RouteRecordMultipleViews['components']
+ children: RouteRecordMultipleViews['children']
+ meta: Exclude<RouteRecordMultipleViews['meta'], void>
+ beforeEnter: RouteRecordMultipleViews['beforeEnter']
leaveGuards: NavigationGuard[]
}
-
-// normalize component/components into components
-export type RouteRecordNormalized = RouteRecordNormalizedCommon &
- // TODO: make it required (monomorphic)
- Pick<
- RouteRecordMultipleViews,
- 'path' | 'name' | 'components' | 'children' | 'meta' | 'beforeEnter'
- >