diff --git a/packages/wouter/src/index.js b/packages/wouter/src/index.js index 8a20f8b..795abed 100644 --- a/packages/wouter/src/index.js +++ b/packages/wouter/src/index.js @@ -230,7 +230,7 @@ export const Link = forwardRef((props, ref) => { const [currentPath, navigate] = useLocationFromRouter(router); const { - to, + to = "", href: targetPath = to, onClick: _onClick, asChild, diff --git a/packages/wouter/test/link.test.tsx b/packages/wouter/test/link.test.tsx index 5208024..204027d 100644 --- a/packages/wouter/test/link.test.tsx +++ b/packages/wouter/test/link.test.tsx @@ -322,4 +322,17 @@ describe(" with `asChild` prop", () => { expect(link).toHaveAttribute("href", "/about"); expect(link).toHaveTextContent("Click Me"); }); + + it("missing href or to won't crash", () => { + const { getByText } = render( + /* @ts-expect-error */ + Click Me + ); + + const link = getByText("Click Me"); + + expect(link.tagName).toBe("A"); + expect(link).toHaveAttribute("href", undefined); + expect(link).toHaveTextContent("Click Me"); + }); });