)
})
- it('resolves an alias with children', () => {
+ it('resolves an alias with children to the alias when using the path', () => {
const children = [{ path: 'one', component, name: 'nested' }]
assertRecordMatch(
{
}
)
})
+
+ it('resolves the original path of the named children of a route with an alias', () => {
+ const children = [{ path: 'one', component, name: 'nested' }]
+ assertRecordMatch(
+ {
+ path: '/parent',
+ alias: '/p',
+ component,
+ children,
+ },
+ { name: 'nested' },
+ {
+ path: '/parent/one',
+ name: 'nested',
+ params: {},
+ matched: [
+ {
+ path: '/parent',
+ children,
+ components,
+ aliasOf: undefined,
+ },
+ { path: '/parent/one', name: 'nested', components },
+ ],
+ }
+ )
+ })
})
describe('LocationAsPath', () => {
// while (i < matchers.length && matcher.score <= matchers[i].score) i++
matchers.splice(i, 0, matcher)
// only add the original record to the name map
- if (matcher.record.name && !matcher.record.aliasOf)
+ if (matcher.record.name && !isAliasRecord(matcher))
matcherMap.set(matcher.record.name, matcher)
}
}
}
+/**
+ * Checks if a record or any of its parent is an alias
+ * @param record
+ */
+function isAliasRecord(record: RouteRecordMatcher | undefined): boolean {
+ while (record) {
+ if (record.record.aliasOf) return true
+ record = record.parent
+ }
+
+ return false
+}
+
export { PathParserOptions }
}
}
- function push(to: RouteLocation): Promise<RouteLocationNormalized> {
+ function push(
+ to: RouteLocation | RouteLocationNormalized
+ ): Promise<RouteLocationNormalized> {
return pushWithRedirect(to, undefined)
}
async function pushWithRedirect(
- to: RouteLocation,
+ to: RouteLocation | RouteLocationNormalized,
redirectedFrom: RouteLocationNormalized | undefined
): Promise<RouteLocationNormalized> {
- const toLocation: RouteLocationNormalized = (pendingLocation = resolve(to))
+ const toLocation: RouteLocationNormalized = (pendingLocation =
+ // Some functions will pass a normalized location and we don't need to resolve it again
+ typeof to === 'object' && 'matched' in to ? to : resolve(to))
const from: RouteLocationNormalized = currentRoute.value
// @ts-ignore: no need to check the string as force do not exist on a string
const force: boolean | undefined = to.force
triggerError(error)
}
- finalizeNavigation(toLocation, from, true, to.replace === true)
+ finalizeNavigation(
+ toLocation,
+ from,
+ true,
+ // RouteLocationNormalized will give undefined
+ (to as RouteLocation).replace === true
+ )
return currentRoute.value
}
- function replace(to: RouteLocation) {
+ function replace(to: RouteLocation | RouteLocationNormalized) {
const location = typeof to === 'string' ? { path: to } : to
return push({ ...location, replace: true })
}