Skip to content

Commit 414a64a

Browse files
committed
feat: replace non-params with segments when buildPath
1 parent c826ed1 commit 414a64a

File tree

9 files changed

+102
-89
lines changed

9 files changed

+102
-89
lines changed

.changeset/silly-foxes-rush.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"astro-nanostores-i18n": minor
3+
"astro-loader-i18n": minor
4+
---
5+
6+
Replace non-params with segments when buildPath

libs/astro-loader-i18n/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"devDependencies": {
3434
"@codecov/vite-plugin": "^1.9.1",
3535
"@eslint/js": "^9.37.0",
36-
"@types/node": "^24.7.0",
36+
"@types/node": "^24.7.1",
3737
"@vitest/coverage-v8": "^3.2.4",
3838
"astro": "^5.14.3",
3939
"astro-utils-i18n": "workspace:*",

libs/astro-nanostores-i18n/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"devDependencies": {
4545
"@codecov/vite-plugin": "^1.9.1",
4646
"@eslint/js": "^9.37.0",
47-
"@types/node": "^24.7.0",
47+
"@types/node": "^24.7.1",
4848
"@vitest/coverage-v8": "^3.2.4",
4949
"astro": "^5.14.3",
5050
"astro-utils-i18n": "workspace:*",

libs/astro-utils-i18n/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"devDependencies": {
3737
"@codecov/vite-plugin": "^1.9.1",
3838
"@eslint/js": "^9.37.0",
39-
"@types/node": "^24.7.0",
39+
"@types/node": "^24.7.1",
4040
"@vitest/coverage-v8": "^3.2.4",
4141
"astro": "^5.14.3",
4242
"eslint": "^9.37.0",

libs/astro-utils-i18n/src/utils/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export function buildPath(routePattern: RoutePattern, segmentValues: Segments, b
7171

7272
return segmentValues[segment.value];
7373
}
74-
return `${segment.value}`;
74+
75+
return segmentValues[segment.value] ?? `${segment.value}`;
7576
})
7677
);
7778
}

libs/astro-utils-i18n/test/utils/__snapshots__/route.spec.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
exports[`buildPath > should build valid paths 1`] = `"/blog/bli/bla/blub/comments/2"`;
44

5+
exports[`buildPath > should replace non params with segments 1`] = `"/blog/bli/bla/blub/kommentare/2"`;
6+
57
exports[`buildPath > should throw if is filled with a path and param is not spread 1`] = `[Error: The segment value "bli/bla/blub" for route segment "slug" contains a slash. Did you forget to add "..." to the route pattern?]`;
68

79
exports[`buildPath > should throw if no segment matches a param 1`] = `[Error: No segment value found for route segment "slug". Did you forget to provide it?]`;

libs/astro-utils-i18n/test/utils/route.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,8 @@ describe("buildPath", () => {
5454
const routePattern = parseRoutePattern("/blog/[...slug]/comments/[commentId]");
5555
expect(buildPath(routePattern, { slug: "bli/bla/blub", commentId: "2" }, "/")).toMatchSnapshot();
5656
});
57+
it("should replace non params with segments", () => {
58+
const routePattern = parseRoutePattern("/blog/[...slug]/comments/[commentId]");
59+
expect(buildPath(routePattern, { slug: "bli/bla/blub", commentId: "2", comments: "kommentare" }, "/")).toMatchSnapshot();
60+
});
5761
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@nx/eslint": "21.6.4",
2424
"@nx/vite": "21.6.4",
2525
"@nx/web": "21.6.4",
26-
"@types/node": "^24.7.0",
26+
"@types/node": "^24.7.1",
2727
"@vitest/ui": "^3.2.4",
2828
"eslint": "^9.37.0",
2929
"eslint-config-prettier": "^10.1.8",

0 commit comments

Comments
 (0)