Skip to content

Commit 34c0c13

Browse files
committed
chore: wip refactor
The idea here was to reuse the experimental router within the actual router. This turns out to be a lot of work without any security of having something working and without breaking changes in the end. So I think it's better to keep two versions of the createRouter function with prefix `EXPERIMENTAL_`. In the end, one code base only uses one of the function so it's fine to keep the code duplicated until v5. This branch is here as a reminder of the failure.
1 parent 794fdd5 commit 34c0c13

File tree

3 files changed

+266
-805
lines changed

3 files changed

+266
-805
lines changed

packages/router/src/experimental/router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ export interface EXPERIMENTAL_RouteRecordNormalized extends NEW_MatcherRecord {
410410
* Arbitrary data attached to the record.
411411
*/
412412
meta: RouteMeta
413+
parent?: EXPERIMENTAL_RouteRecordNormalized
413414
}
414415

415416
function normalizeRouteRecord(

packages/router/src/matcher/pathMatcher.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@ export interface RouteRecordMatcher extends PathParser {
1616
alias: RouteRecordMatcher[]
1717
}
1818

19+
export function NEW_createRouteRecordMatcher(
20+
record: Readonly<RouteRecord>,
21+
parent: RouteRecordMatcher | undefined,
22+
options?: PathParserOptions
23+
): RouteRecordMatcher {
24+
const parser = tokensToParser(tokenizePath(record.path), options)
25+
26+
const matcher: RouteRecordMatcher = assign(parser, {
27+
record,
28+
parent,
29+
// these needs to be populated by the parent
30+
children: [],
31+
alias: [],
32+
})
33+
34+
if (parent) {
35+
// both are aliases or both are not aliases
36+
// we don't want to mix them because the order is used when
37+
// passing originalRecord in Matcher.addRoute
38+
if (!matcher.record.aliasOf === !parent.record.aliasOf)
39+
parent.children.push(matcher)
40+
}
41+
42+
return matcher
43+
}
44+
1945
export function createRouteRecordMatcher(
2046
record: Readonly<RouteRecord>,
2147
parent: RouteRecordMatcher | undefined,

0 commit comments

Comments
 (0)