Skip to content

Commit 2fae6d9

Browse files
authored
href replaces splats (#13593)
1 parent 8389d48 commit 2fae6d9

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

.changeset/unlucky-pigs-chew.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"react-router": patch
3+
---
4+
5+
href replaces splats `*`
6+
7+
```ts
8+
const a = href("/products/*", { "*": "/1/edit" });
9+
// -> /products/1/edit
10+
```

packages/react-router/__tests__/href-test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ describe("href", () => {
1717
);
1818
});
1919

20+
it("works with splats", () => {
21+
expect(href("/a/*", { "*": "b/c" })).toBe("/a/b/c");
22+
});
23+
2024
it("throws when required params are missing", () => {
2125
expect(() => href("/a/:b")).toThrow(
2226
`Path '/a/:b' requires param 'b' but it was not provided`

packages/react-router/lib/href.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export function href<Path extends keyof Args>(
3030
return path
3131
.split("/")
3232
.map((segment) => {
33+
if (segment === "*") {
34+
return params ? params["*"] : undefined;
35+
}
36+
3337
const match = segment.match(/^:([\w-]+)(\?)?/);
3438
if (!match) return segment;
3539
const param = match[1];

0 commit comments

Comments
 (0)