+9
-1
@@ -50,2 +50,4 @@ import { parse } from 'regexparam'; | ||
| ssrSearch: undefined, | ||
| // customizes how `href` props are transformed for <Link /> | ||
| hrefs: (x) => x, | ||
| }; | ||
@@ -136,2 +138,5 @@ | ||
| // hooks can define their own `href` formatter (e.g. for hash location) | ||
| props.hrefs = props.hrefs ?? props.hook?.hrefs; | ||
| // what is happening below: to avoid unnecessary rerenders in child components, | ||
@@ -236,3 +241,6 @@ // we ensure that the router object reference is stable, unless there are any | ||
| // handle nested routers and absolute paths | ||
| const href = _href[0] === "~" ? _href.slice(1) : router.base + _href; | ||
| const href = router.hrefs( | ||
| _href[0] === "~" ? _href.slice(1) : router.base + _href, | ||
| router // pass router as a second argument for convinience | ||
| ); | ||
@@ -239,0 +247,0 @@ return asChild && isValidElement(children) |
@@ -49,2 +49,4 @@ import { useSyncExternalStore } from './react-deps.js'; | ||
| useHashLocation.hrefs = (href) => "#" + href; | ||
| export { navigate, useHashLocation }; |
+1
-1
| { | ||
| "name": "wouter", | ||
| "version": "3.1.0-dev.6815e69", | ||
| "version": "3.1.0", | ||
| "description": "Minimalist-friendly ~1.5KB router for React", | ||
@@ -5,0 +5,0 @@ "type": "module", |
+3
-1
@@ -519,3 +519,3 @@ <div align="center"> | ||
| ### `<Router hook={hook} parser={fn} base={basepath} />` | ||
| ### `<Router hook={hook} parser={fn} base={basepath} hrefs={fn} />` | ||
@@ -557,2 +557,4 @@ Unlike _React Router_, routes in wouter **don't have to be wrapped in a top-level component**. An | ||
| - `hrefs: (href: boolean) => string` — a function for transforming `href` attribute of an `<a />` element rendered by `Link`. It is used to support hash-based routing. By default, `href` attribute is the same as the `href` or `to` prop of a `Link`. A location hook can also define a `hook.hrefs` property, in this case the `href` will be inferred. | ||
| ## FAQ and Code Recipes | ||
@@ -559,0 +561,0 @@ |
@@ -10,2 +10,4 @@ import { | ||
| export type HrefsFormatter = (href: string, router: RouterObject) => string; | ||
| // the object returned from `useRouter` | ||
@@ -20,2 +22,3 @@ export interface RouterObject { | ||
| readonly ssrSearch?: SearchString; | ||
| readonly hrefs: HrefsFormatter; | ||
| } | ||
@@ -31,2 +34,3 @@ | ||
| ssrSearch?: SearchString; | ||
| hrefs?: HrefsFormatter; | ||
| }; |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
61014
1.37%692
1.62%1
-50%912
0.22%