Skip to content

Commit

Permalink
useHashLocation uses its own hrefs method.
Browse files Browse the repository at this point in the history
  • Loading branch information
molefrog committed Mar 11, 2024
1 parent c2d71c7 commit 62060a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/wouter/src/use-hash-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ export const useHashLocation = ({ ssrPath = "/" } = {}) => [
),
navigate,
];

useHashLocation.hrefs = (href) => "#" + href;
12 changes: 11 additions & 1 deletion packages/wouter/test/use-hash-location.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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(
<Router hook={useHashLocation}>
<Link href="/app" data-testid="link" />
</Router>
);

expect(getByTestId("link")).toHaveAttribute("href", "#/app");
});

0 comments on commit 62060a1

Please sign in to comment.