@@ -87,6 +87,19 @@ const childDefaultRawRecord: EXPERIMENTAL_RouteRecord_Matchable = {
8787 parent : parentWithRedirectRecord ,
8888}
8989
90+ const aliasRecordOriginal = normalizeRouteRecord ( {
91+ // path: '/basic',
92+ // alias: '/basic-alias',
93+ name : Symbol ( 'basic-alias' ) ,
94+ path : new MatcherPatternPathStatic ( '/basic' ) ,
95+ components : { default : components . Foo } ,
96+ } )
97+ const aliasRecord = normalizeRouteRecord ( {
98+ ...aliasRecordOriginal ,
99+ path : new MatcherPatternPathStatic ( '/basic-alias' ) ,
100+ aliasOf : aliasRecordOriginal ,
101+ } )
102+
90103const aliasParentRecord = normalizeRouteRecord ( {
91104 name : Symbol ( 'aliases' ) ,
92105 path : new MatcherPatternPathStatic ( '/aliases' ) ,
@@ -258,13 +271,8 @@ const routeRecords: EXPERIMENTAL_RouteRecord_Matchable[] = [
258271 } ,
259272
260273 // aliases
261- {
262- // path: '/basic',
263- // alias: '/basic-alias',
264- name : Symbol ( 'basic-alias' ) ,
265- path : new MatcherPatternPathStatic ( '/basic-alias' ) ,
266- components : { default : components . Foo } ,
267- } ,
274+ aliasRecordOriginal ,
275+ aliasRecord ,
268276
269277 aliasChildOneRecord ,
270278 aliasChildTwoRawRecord ,
@@ -758,7 +766,26 @@ describe('Experimental Router', () => {
758766 } )
759767
760768 describe ( 'alias' , ( ) => {
761- it . skip ( 'does not navigate to alias if already on original record' , async ( ) => { } )
769+ it ( 'navigates to alias' , async ( ) => {
770+ const { router } = await newRouter ( )
771+ await router . push ( '/basic-alias' )
772+ expect ( router . currentRoute . value . path ) . toBe ( '/basic-alias' )
773+ expect ( router . currentRoute . value . matched . at ( 0 ) ) . toBe ( aliasRecord )
774+ expect ( router . currentRoute . value . matched . at ( 0 ) ?. aliasOf ) . toBe (
775+ aliasRecordOriginal
776+ )
777+ } )
778+
779+ it ( 'does not navigate to alias if already on original record' , async ( ) => {
780+ const { router } = await newRouter ( )
781+ const spy = vi . fn ( )
782+ await router . push ( '/basic' )
783+ expect ( router . currentRoute . value . path ) . toBe ( '/basic' )
784+ router . beforeEach ( spy )
785+ await router . push ( '/basic-alias' )
786+ expect ( spy ) . not . toHaveBeenCalled ( )
787+ expect ( router . currentRoute . value . path ) . toBe ( '/basic' )
788+ } )
762789
763790 it . skip ( 'does not navigate to alias with children if already on original record' , async ( ) => { } )
764791
0 commit comments