parent: parentWithRedirectRecord,
}
+const aliasRecordOriginal = normalizeRouteRecord({
+ // path: '/basic',
+ // alias: '/basic-alias',
+ name: Symbol('basic-alias'),
+ path: new MatcherPatternPathStatic('/basic'),
+ components: { default: components.Foo },
+})
+const aliasRecord = normalizeRouteRecord({
+ ...aliasRecordOriginal,
+ path: new MatcherPatternPathStatic('/basic-alias'),
+ aliasOf: aliasRecordOriginal,
+})
+
const aliasParentRecord = normalizeRouteRecord({
name: Symbol('aliases'),
path: new MatcherPatternPathStatic('/aliases'),
},
// aliases
- {
- // path: '/basic',
- // alias: '/basic-alias',
- name: Symbol('basic-alias'),
- path: new MatcherPatternPathStatic('/basic-alias'),
- components: { default: components.Foo },
- },
+ aliasRecordOriginal,
+ aliasRecord,
aliasChildOneRecord,
aliasChildTwoRawRecord,
})
describe('alias', () => {
- it.skip('does not navigate to alias if already on original record', async () => {})
+ it('navigates to alias', async () => {
+ const { router } = await newRouter()
+ await router.push('/basic-alias')
+ expect(router.currentRoute.value.path).toBe('/basic-alias')
+ expect(router.currentRoute.value.matched.at(0)).toBe(aliasRecord)
+ expect(router.currentRoute.value.matched.at(0)?.aliasOf).toBe(
+ aliasRecordOriginal
+ )
+ })
+
+ it('does not navigate to alias if already on original record', async () => {
+ const { router } = await newRouter()
+ const spy = vi.fn()
+ await router.push('/basic')
+ expect(router.currentRoute.value.path).toBe('/basic')
+ router.beforeEach(spy)
+ await router.push('/basic-alias')
+ expect(spy).not.toHaveBeenCalled()
+ expect(router.currentRoute.value.path).toBe('/basic')
+ })
it.skip('does not navigate to alias with children if already on original record', async () => {})
*/
export interface EXPERIMENTAL_RouteRecord_Base
extends EXPERIMENTAL_ResolverRecord_Base {
- // TODO:
/**
* Where to redirect if the route is directly matched. The redirection happens
* before any navigation guard and triggers a new navigation with the new
// TODO:
/**
- * Aliases for the record. Allows defining extra paths that will behave like a
- * copy of the record. Allows having paths shorthands like `/users/:id` and
- * `/u/:id`. All `alias` and `path` values must share the same params.
+ * References another record if this record is an alias of it.
*/
- // alias?: string | string[]
+ aliasOf?: unknown
// TODO: deprecate, expose utils to compare resolved routes, and document
// how to create a meta field that does the same
// must be defined as non enumerable because it contains modules
// mods: {},
props: {},
+ // TODO :make it optional as it changes nothing
parent: null,
+ // not having the property changes nothing
+ // aliasOf: null,
...record,
// FIXME: to be removed
instances: {},