From a01973ec0d47e4ed297fac3eac74d86c4bb2a3e4 Mon Sep 17 00:00:00 2001 From: Alexey Taktarov Date: Tue, 27 Feb 2024 12:54:41 +0100 Subject: [PATCH] `useHashLocation` uses its own `hrefs` method. --- packages/wouter/src/use-hash-location.js | 2 ++ packages/wouter/test/use-hash-location.test.tsx | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/wouter/src/use-hash-location.js b/packages/wouter/src/use-hash-location.js index eb8fdc34..562bc2d3 100644 --- a/packages/wouter/src/use-hash-location.js +++ b/packages/wouter/src/use-hash-location.js @@ -45,3 +45,5 @@ export const useHashLocation = ({ ssrPath = "/" } = {}) => [ ), navigate, ]; + +useHashLocation.hrefs = (href) => "#" + href; diff --git a/packages/wouter/test/use-hash-location.test.tsx b/packages/wouter/test/use-hash-location.test.tsx index b6fc15ec..77b2b0a1 100644 --- a/packages/wouter/test/use-hash-location.test.tsx +++ b/packages/wouter/test/use-hash-location.test.tsx @@ -2,7 +2,7 @@ import { it, expect, beforeEach } from "vitest"; import { renderHook, render } from "@testing-library/react"; import { renderToStaticMarkup } from "react-dom/server"; -import { Router, Route, useLocation } from "wouter"; +import { Router, Route, useLocation, Link } from "wouter"; import { useHashLocation } from "wouter/use-hash-location"; import { waitForHashChangeEvent } from "./test-utils"; @@ -186,3 +186,13 @@ it("works even if `hashchange` listeners are called asynchronously ", async () = expect(paths).toEqual(["/a"]); unmount(); }); + +it("defines a custom way of rendering link hrefs", () => { + const { getByTestId } = render( + + + + ); + + expect(getByTestId("link")).toHaveAttribute("href", "#/app"); +});