Skip to content

Commit 82e24e7

Browse files
authored
docs: Add ToC & mention of locationStub() util (#117)
* docs: Add table of contents to ReadMe for easier nav * docs: Add locationStub utility to ReadMe
1 parent d853318 commit 82e24e7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@ Isomorphic async tools for Preact.
88
- Generate static HTML for your app using `prerender()`, waiting for `lazy()` components and data dependencies.
99
- Implement async-aware client and server-side routing using `<Router>`, including seamless async transitions.
1010

11+
---
12+
13+
- [Routing](#routing)
14+
- [Prerendering](#prerendering)
15+
- [Nested Routing](#nested-routing)
16+
- [API Docs](#api-docs)
17+
- [\<LocationProvider\>](#locationprovider)
18+
- [\<Router\>](#router)
19+
- [\<Route\>](#route)
20+
- [Path Segment Matching](#path-segment-matching)
21+
- [useLocation()](#uselocation)
22+
- [useRoute()](#useroute)
23+
- [lazy()](#lazy)
24+
- [\<ErrorBoundary\>](#errorboundary)
25+
- [hydrate()](#hydrate)
26+
- [prerender()](#prerender)
27+
- [locationStub()](#locationstub)
28+
29+
---
30+
1131
## Routing
1232

1333
`preact-iso` offers a simple router for Preact with conventional and hooks-based APIs. The `<Router>` component is async-aware: when transitioning from one route to another, if the incoming route suspends (throws a Promise), the outgoing route is preserved until the new one becomes ready.
@@ -378,6 +398,18 @@ const App = () => (
378398
const { html, links } = await prerender(<App />);
379399
```
380400

401+
### `locationStub`
402+
403+
A utility function to imitate the `location` object in a non-browser environment. Our router relies upon this to function, so if you are using `preact-iso` outside of a browser context and are not prerendering via `@preact/preset-vite` (which does this for you), you can use this utility to set a stubbed `location` object.
404+
405+
```js
406+
import { locationStub } from 'preact-iso/prerender';
407+
408+
locationStub('/foo/bar?baz=qux#quux');
409+
410+
console.log(location.pathname); // "/foo/bar"
411+
```
412+
381413
## License
382414

383415
[MIT](./LICENSE)

0 commit comments

Comments
 (0)