Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/unlucky-pigs-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"react-router": patch
---

href replaces splats `*`

```ts
const a = href("/products/*", { "*": "/1/edit" });
// -> /products/1/edit
```
4 changes: 4 additions & 0 deletions packages/react-router/__tests__/href-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ describe("href", () => {
);
});

it("works with splats", () => {
expect(href("/a/*", { "*": "b/c" })).toBe("/a/b/c");
});

it("throws when required params are missing", () => {
expect(() => href("/a/:b")).toThrow(
`Path '/a/:b' requires param 'b' but it was not provided`
Expand Down
4 changes: 4 additions & 0 deletions packages/react-router/lib/href.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export function href<Path extends keyof Args>(
return path
.split("/")
.map((segment) => {
if (segment === "*") {
return params ? params["*"] : undefined;
}

const match = segment.match(/^:([\w-]+)(\?)?/);
if (!match) return segment;
const param = match[1];
Expand Down