resolved.matched = record.map(normalizeRouteRecord)
// allow passing an expect.any(Array)
else if (Array.isArray(resolved.matched))
- resolved.matched = resolved.matched.map(normalizeRouteRecord as any)
+ resolved.matched = resolved.matched.map(m => ({
+ ...normalizeRouteRecord(m as any),
+ aliasOf: m.aliasOf,
+ }))
}
// allows not passing params
const startCopy = {
...start,
- matched: start.matched.map(normalizeRouteRecord),
+ matched: start.matched.map(m => ({
+ ...normalizeRouteRecord(m),
+ aliasOf: m.aliasOf,
+ })),
}
// make matched non enumerable
path: '/home',
name: 'Home',
components,
+ aliasOf: expect.objectContaining({ name: 'Home', path: '/' }),
+ meta: { foo: true },
+ },
+ ],
+ }
+ )
+ })
+
+ it.todo('multiple aliases')
+ it.todo('resolve named child with parent with alias')
+
+ it('resolves the original record by name', () => {
+ assertRecordMatch(
+ {
+ path: '/',
+ alias: '/home',
+ name: 'Home',
+ components,
+ meta: { foo: true },
+ },
+ { name: 'Home' },
+ {
+ name: 'Home',
+ path: '/',
+ params: {},
+ meta: { foo: true },
+ matched: [
+ {
+ path: '/',
+ name: 'Home',
+ components,
+ aliasOf: undefined,
meta: { foo: true },
},
],
name: 'nested',
params: {},
matched: [
- { path: '/p', children, components },
+ {
+ path: '/p',
+ children,
+ components,
+ aliasOf: expect.objectContaining({ path: '/parent' }),
+ },
{ path: '/p/one', name: 'nested', components },
],
}
'path' | 'name' | 'components' | 'children' | 'meta' | 'beforeEnter'
> {
leaveGuards?: any
+ aliasOf: RouteRecordViewLoose | undefined
}
// @ts-ignore we are intentionally overriding the type
>/nested/nested/nested</router-link
>
</li>
+ <li>
+ <router-link to="/anidado">/anidado</router-link>
+ </li>
+ <li>
+ <router-link to="/anidado/nested">/anidado/nested</router-link>
+ </li>
+ <li>
+ <router-link to="/anidado/nested/nested"
+ >/anidado/nested/nested</router-link
+ >
+ </li>
<li>
<router-link to="/long-0">/long-0</router-link>
</li>
{ path: '/:data(.*)', component: NotFound, name: 'NotFound' },
{
path: '/nested',
+ alias: '/anidado',
component: Nested,
name: 'Nested',
children: [
const options: PathParserOptions = { ...globalOptions, ...record.options }
// generate an array of records to correctly handle aliases
const normalizedRecords: RouteRecordNormalized[] = [mainNormalizedRecord]
- // TODO: remember aliases in records to allow active in router-link
if ('alias' in record) {
const aliases =
typeof record.alias === 'string' ? [record.alias] : record.alias!
normalizedRecords.push({
...mainNormalizedRecord,
path: alias,
+ aliasOf: mainNormalizedRecord,
})
}
}
// console.log('END i is', { i })
// while (i < matchers.length && matcher.score <= matchers[i].score) i++
matchers.splice(i, 0, matcher)
- if (matcher.record.name) matcherMap.set(matcher.record.name, matcher)
+ // only add the original record to the name map
+ if (matcher.record.name && !matcher.record.aliasOf)
+ matcherMap.set(matcher.record.name, matcher)
}
/**
let parentMatcher: RouteRecordMatcher | void = matcher
while (parentMatcher) {
// reversed order so parents are at the beginning
+ // const { record } = parentMatcher
+ // TODO: check resolving child routes by path when parent has an alias
matched.unshift(parentMatcher.record)
parentMatcher = parentMatcher.parent
}
beforeEnter,
meta: record.meta || {},
leaveGuards: [],
+ aliasOf: undefined,
}
}
meta: Exclude<RouteRecordMultipleViews['meta'], void>
beforeEnter: RouteRecordMultipleViews['beforeEnter']
leaveGuards: NavigationGuard[]
+ aliasOf: RouteRecordNormalized | undefined
}