Skip to content

Commit 7788fbc

Browse files
fix(plugin-history-sync): change asterisk(*) priority to lowest (#480)
1 parent fb725d9 commit 7788fbc

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

.changeset/chilled-meals-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@stackflow/plugin-history-sync": patch
3+
---
4+
5+
change asterisk(`*`) priority to lowest

extensions/plugin-history-sync/src/makeTemplate.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ export function makeTemplate<T>(
5151
) {
5252
const pattern = new UrlPattern(`${path}(/)`, urlPatternOptions);
5353

54+
const onlyAsterisk = path === "*" || path === "/*";
55+
56+
const variableCount = onlyAsterisk
57+
? Number.POSITIVE_INFINITY
58+
: (pattern as any).names.length;
59+
5460
return {
5561
fill(params: { [key: string]: string | undefined }) {
5662
const pathname = pattern.stringify(params);
@@ -99,6 +105,6 @@ export function makeTemplate<T>(
99105

100106
return decode ? decode(params) : params;
101107
},
102-
variableCount: (pattern as any).names.length,
108+
variableCount,
103109
};
104110
}

extensions/plugin-history-sync/src/sortActivityRoutes.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,19 @@ test("sortActivityRoutes - 한 액티비티가 여러 라우트를 가지는 경
2525
{ activityName: "B", path: "/hello/:param" },
2626
]);
2727
});
28+
29+
test("sortActivityRoutes - *이 들어간 경우 해당 라우트를 맨 뒤로 옮깁니다", () => {
30+
const routes = sortActivityRoutes([
31+
{ activityName: "A", path: "*" },
32+
{ activityName: "A", path: "/detailed/*" },
33+
{ activityName: "B", path: "/:hello/:world" },
34+
{ activityName: "C", path: "/:hello/:world/:foo/:bar" },
35+
]);
36+
37+
expect(routes).toStrictEqual([
38+
{ activityName: "A", path: "/detailed/*" },
39+
{ activityName: "B", path: "/:hello/:world" },
40+
{ activityName: "C", path: "/:hello/:world/:foo/:bar" },
41+
{ activityName: "A", path: "*" },
42+
]);
43+
});

0 commit comments

Comments
 (0)