Skip to content

Commit cc419eb

Browse files
committed
chore: update README docs for data router
1 parent 6e1068f commit cc419eb

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,72 @@ export default function Header() {
103103
}
104104
```
105105

106+
### DataRouter
107+
108+
Alternative you can use `createDataRouter`
109+
110+
```tsx
111+
import { createDataRouter, NotFound, RouterErrorBoundary } from "preact-hashish-router";
112+
import { lazy } from "preact/compat";
113+
import { AllLevelWildcard } from "./routes/AllLevelWildcard";
114+
import { Home } from "./routes/Home";
115+
import { OneLevelWildcard } from "./routes/OneLevelWildcard";
116+
import { ProductDetails } from "./routes/ProductDetails";
117+
118+
const AboutLazy = lazy(() => import("./routes/About"));
119+
120+
const DataRouter = createDataRouter([
121+
{
122+
path: "/",
123+
element: <Home />,
124+
children: [
125+
{
126+
path: "about",
127+
lazy: true,
128+
fallback: <h1>Loading About...</h1>,
129+
element: <AboutLazy />,
130+
children: [
131+
{
132+
path: "test",
133+
element: <h1>About/test</h1>,
134+
},
135+
],
136+
},
137+
{
138+
path: "product/:id",
139+
element: <ProductDetails />,
140+
},
141+
{
142+
path: "one-level-wildcard/*",
143+
element: <OneLevelWildcard />,
144+
},
145+
{
146+
path: "all-level-wildcard/**",
147+
element: <AllLevelWildcard />,
148+
},
149+
],
150+
},
151+
]);
152+
153+
export function App() {
154+
return (
155+
<RouterErrorBoundary>
156+
<DataRouter
157+
onRouteDidChange={(url) => {
158+
console.log("onRouteDidChange", url);
159+
}}
160+
onBeforeRouteChange={(url) => {
161+
console.log("onBeforeRouteChange", url);
162+
}}
163+
>
164+
<NotFound element={<h1>Custom Not Found Element</h1>} />
165+
</DataRouter>
166+
</RouterErrorBoundary>
167+
);
168+
}
169+
```
170+
106171
## Development
107172

108173
If you have any improvements or find any issues, feel free to contribute or open an issue in the associated repository.
174+

0 commit comments

Comments
 (0)