2121 * - ✅ Meta field merging from parent to child
2222 * - ❌ Dynamic routing (addRoute, removeRoute, hasRoute)
2323 * - ❌ Aliases (not implemented in experimental router)
24- * - ❌ Redirects (limited support)
25- * - ❌ Complex object-based resolve (may work differently)
24+ * - ✅ Redirects (limited support)
25+ * - ✅ Complex object-based resolve (may work differently)
2626 * - ❌ beforeEnter guards (not implemented)
27- * - ❌ Param validation/casting (works differently)
28- *
29- * PASSING TESTS: 26/71 (45 skipped due to experimental router limitations)
27+ * - ✅ Param validation/casting (works differently)
3028 */
3129
3230import fakePromise from 'faked-promise'
@@ -57,45 +55,13 @@ import { START_LOCATION_NORMALIZED } from '../location'
5755import { vi , describe , expect , it , beforeAll } from 'vitest'
5856import { mockWarn } from '../../__tests__/vitest-mock-warn'
5957
60- // Create dynamic pattern matchers using the proper constructor
61- const paramMatcher = new MatcherPatternPathDynamic (
62- / ^ \/ p \/ ( [ ^ / ] + ) $ / ,
63- { p : [ { } ] } ,
64- [ 'p' , 1 ]
65- )
66-
67- const optionalMatcher = new MatcherPatternPathDynamic (
68- / ^ \/ o p t i o n a l (?: \/ ( [ ^ / ] + ) ) ? $ / ,
69- { p : [ ] } ,
70- [ 'optional' , 1 ]
71- )
72-
73- const repeatMatcher = new MatcherPatternPathDynamic (
74- / ^ \/ r e p e a t \/ ( .+ ) $ / ,
75- { r : [ { } , true ] } ,
76- [ 'repeat' , 0 ]
77- )
78-
79- const catchAllMatcher = new MatcherPatternPathDynamic (
80- / ^ \/ ( .* ) $ / i,
81- { pathMatch : [ ] } ,
82- [ 0 ] ,
83- null
84- )
85-
86- // Create experimental route records using proper structure
87- // First create parent records
88- const parentRawRecord : EXPERIMENTAL_RouteRecord_Matchable = {
58+ const parentRecord = normalizeRouteRecord ( {
8959 name : 'parent' ,
9060 path : new MatcherPatternPathStatic ( '/parent' ) ,
9161 components : { default : components . Foo } ,
9262 meta : { fromParent : 'foo' } ,
93- }
94-
95- // Normalize parent record
96- const parentRecord = normalizeRouteRecord ( parentRawRecord )
63+ } )
9764
98- // Create child record with parent reference
9965const childRawRecord : EXPERIMENTAL_RouteRecord_Matchable = {
10066 name : 'parent-child' ,
10167 path : new MatcherPatternPathStatic ( '/parent/child' ) ,
@@ -107,14 +73,11 @@ const childRawRecord: EXPERIMENTAL_RouteRecord_Matchable = {
10773// NOTE: this redirect is not needed, the router should match by default the child
10874// and it's better to simply not name the route to make it non matchable with
10975// the new router
110- const parentWithRedirectRawRecord : EXPERIMENTAL_RouteRecord_Matchable = {
76+ const parentWithRedirectRecord = normalizeRouteRecord ( {
11177 name : 'parent-with-redirect' ,
11278 path : new MatcherPatternPathStatic ( '/parent-with-redirect' ) ,
11379 redirect : { name : 'child-for-redirect' } ,
114- }
115- const parentWithRedirectRecord = normalizeRouteRecord (
116- parentWithRedirectRawRecord
117- )
80+ } )
11881
11982const childDefaultRawRecord : EXPERIMENTAL_RouteRecord_Matchable = {
12083 name : 'child-for-redirect' ,
@@ -124,6 +87,29 @@ const childDefaultRawRecord: EXPERIMENTAL_RouteRecord_Matchable = {
12487 parent : parentWithRedirectRecord ,
12588}
12689
90+ const aliasParentRecord = normalizeRouteRecord ( {
91+ name : Symbol ( 'aliases' ) ,
92+ path : new MatcherPatternPathStatic ( '/aliases' ) ,
93+ // alias: ['/aliases1', '/aliases2'],
94+ components : { default : components . Nested } ,
95+ } )
96+
97+ const aliasChildOneRecord = normalizeRouteRecord ( {
98+ name : Symbol ( 'one' ) ,
99+ path : new MatcherPatternPathStatic ( '/aliases/one' ) ,
100+ // alias: ['o', 'o2'],
101+ components : { default : components . Foo } ,
102+ parent : aliasParentRecord ,
103+ } )
104+
105+ const aliasChildTwoRawRecord : EXPERIMENTAL_RouteRecord_Matchable = {
106+ name : Symbol ( 'two' ) ,
107+ path : new MatcherPatternPathStatic ( '/aliases/one/two' ) ,
108+ // alias: ['t', 't2'],
109+ components : { default : components . Bar } ,
110+ parent : aliasChildOneRecord ,
111+ }
112+
127113// Create all route records
128114const routeRecords : EXPERIMENTAL_RouteRecord_Matchable [ ] = [
129115 {
@@ -192,18 +178,28 @@ const routeRecords: EXPERIMENTAL_RouteRecord_Matchable[] = [
192178 } ,
193179 {
194180 name : 'Param' ,
195- path : paramMatcher ,
181+ path : new MatcherPatternPathDynamic ( / ^ \/ p \/ ( [ ^ / ] + ) $ / , { p : [ { } ] } , [
182+ 'p' ,
183+ 1 ,
184+ ] ) ,
196185 components : { default : components . Bar } ,
197186 } ,
198187
199188 {
200189 name : 'optional' ,
201- path : optionalMatcher ,
190+ path : new MatcherPatternPathDynamic (
191+ / ^ \/ o p t i o n a l (?: \/ ( [ ^ / ] + ) ) ? $ / ,
192+ { p : [ ] } ,
193+ [ 'optional' , 1 ]
194+ ) ,
202195 components : { default : components . Bar } ,
203196 } ,
204197 {
205198 name : 'repeat' ,
206- path : repeatMatcher ,
199+ path : new MatcherPatternPathDynamic ( / ^ \/ r e p e a t \/ ( .+ ) $ / , { r : [ { } , true ] } , [
200+ 'repeat' ,
201+ 0 ,
202+ ] ) ,
207203 components : { default : components . Bar } ,
208204 } ,
209205 {
@@ -213,7 +209,7 @@ const routeRecords: EXPERIMENTAL_RouteRecord_Matchable[] = [
213209 } ,
214210
215211 childRawRecord ,
216- parentRawRecord ,
212+ parentRecord ,
217213
218214 childDefaultRawRecord ,
219215 parentWithRedirectRecord ,
@@ -261,16 +257,35 @@ const routeRecords: EXPERIMENTAL_RouteRecord_Matchable[] = [
261257 } ) ,
262258 } ,
263259
260+ // 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+ } ,
268+
269+ aliasChildOneRecord ,
270+ aliasChildTwoRawRecord ,
271+
264272 {
265273 name : 'catch-all' ,
266- path : catchAllMatcher ,
274+ path : new MatcherPatternPathDynamic (
275+ / ^ \/ ( .* ) $ / i,
276+ { pathMatch : [ ] } ,
277+ [ 0 ] ,
278+ null
279+ ) ,
267280 components : { default : components . Home } ,
268281 } ,
269282]
270283
271- // Normalize all records
272284const experimentalRoutes = routeRecords . map ( record =>
273- normalizeRouteRecord ( record )
285+ 'mods' in record
286+ ? // avoid double normalizing to keep same references
287+ ( record as ReturnType < typeof normalizeRouteRecord > )
288+ : normalizeRouteRecord ( record )
274289)
275290
276291async function newRouter (
0 commit comments