@uxf/router 11.124.0 → 11.126.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -28
- package/package.json +3 -3
- package/sitemap-generator.d.ts +2 -2
package/README.md
CHANGED
|
@@ -98,17 +98,13 @@ Add configuration to `tsconfig.json`
|
|
|
98
98
|
|
|
99
99
|
```json
|
|
100
100
|
{
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
"@app-routes/client": [
|
|
108
|
-
"routes/client"
|
|
109
|
-
]
|
|
101
|
+
"compilerOptions": {
|
|
102
|
+
"baseUrl": "./src",
|
|
103
|
+
"paths": {
|
|
104
|
+
"@app-routes": ["routes"],
|
|
105
|
+
"@app-routes/client": ["routes/client"]
|
|
106
|
+
}
|
|
110
107
|
}
|
|
111
|
-
}
|
|
112
108
|
}
|
|
113
109
|
```
|
|
114
110
|
|
|
@@ -136,11 +132,7 @@ const [query, { push, replace }] = useQueryParamsStatic("route-name");
|
|
|
136
132
|
import Link from "next/link";
|
|
137
133
|
import { routeToUrl } from "@app-routes";
|
|
138
134
|
|
|
139
|
-
export default () => (
|
|
140
|
-
<Link href={routeToUrl("blog/detail", { id: 12 })}>
|
|
141
|
-
Hello world
|
|
142
|
-
</Link>
|
|
143
|
-
)
|
|
135
|
+
export default () => <Link href={routeToUrl("blog/detail", { id: 12 })}>Hello world</Link>;
|
|
144
136
|
```
|
|
145
137
|
|
|
146
138
|
## RouteMatcher
|
|
@@ -158,7 +150,7 @@ const routeMatcher = createRouteMatcher("admin/index");
|
|
|
158
150
|
function MyComponent() {
|
|
159
151
|
const router = useRouter();
|
|
160
152
|
const isRouteActive = routeMatcher(router);
|
|
161
|
-
|
|
153
|
+
|
|
162
154
|
return <div>{isRouteActive ? "active" : "not active"}</div>;
|
|
163
155
|
}
|
|
164
156
|
```
|
|
@@ -169,7 +161,7 @@ function MyComponent() {
|
|
|
169
161
|
function createPathnameRouteMatcher(path: string): RouteMatcher {
|
|
170
162
|
return (router) => {
|
|
171
163
|
return router.pathname.startsWith(path);
|
|
172
|
-
}
|
|
164
|
+
};
|
|
173
165
|
}
|
|
174
166
|
```
|
|
175
167
|
|
|
@@ -184,7 +176,7 @@ function createCustomRouteMatcher(): RouteMatcher {
|
|
|
184
176
|
} else if (route === "admin/form") {
|
|
185
177
|
// do something
|
|
186
178
|
}
|
|
187
|
-
}
|
|
179
|
+
};
|
|
188
180
|
}
|
|
189
181
|
```
|
|
190
182
|
|
|
@@ -193,10 +185,7 @@ function createCustomRouteMatcher(): RouteMatcher {
|
|
|
193
185
|
```tsx
|
|
194
186
|
import { mergeRouteMatchers } from "@uxf/router";
|
|
195
187
|
|
|
196
|
-
const routeMatcher = mergeRouteMatchers([
|
|
197
|
-
createRouteMatcher("admin/index"),
|
|
198
|
-
createRouteMatcher("admin/form"),
|
|
199
|
-
]);
|
|
188
|
+
const routeMatcher = mergeRouteMatchers([createRouteMatcher("admin/index"), createRouteMatcher("admin/form")]);
|
|
200
189
|
```
|
|
201
190
|
|
|
202
191
|
## Type-safe route params
|
|
@@ -206,7 +195,7 @@ import { GetRouteSchema } from "@app-routes";
|
|
|
206
195
|
|
|
207
196
|
const blogProps: GetRouteSchema<"blog/detail"> = {
|
|
208
197
|
id: 1,
|
|
209
|
-
}
|
|
198
|
+
};
|
|
210
199
|
```
|
|
211
200
|
|
|
212
201
|
## GetStaticProps
|
|
@@ -217,7 +206,7 @@ import { queryParamToNumber } from "@uxf/router";
|
|
|
217
206
|
|
|
218
207
|
export const getStaticProps: GetStaticProps<"blog/detail"> = (context) => {
|
|
219
208
|
const id = queryParamToNumber(context.params?.id); // context.params is of type { id: number } | undefined
|
|
220
|
-
}
|
|
209
|
+
};
|
|
221
210
|
```
|
|
222
211
|
|
|
223
212
|
## GetServerSideProps
|
|
@@ -228,7 +217,7 @@ import { queryParamToNumber } from "@uxf/router";
|
|
|
228
217
|
|
|
229
218
|
export const getServerSideProps: GetServerSideProps<"blog/detail"> = (context) => {
|
|
230
219
|
const id = queryParamToNumber(context.params?.id); // context.params is of type { id: number } | undefined
|
|
231
|
-
}
|
|
220
|
+
};
|
|
232
221
|
```
|
|
233
222
|
|
|
234
223
|
## Sitemap
|
|
@@ -240,11 +229,11 @@ Create sitemap items
|
|
|
240
229
|
|
|
241
230
|
import { createSitemapGenerator, routeToUrl } from "@app-routes";
|
|
242
231
|
|
|
243
|
-
export const sitemapItems = createSitemapGenerator({baseUrl:
|
|
232
|
+
export const sitemapItems = createSitemapGenerator({ baseUrl: "http://localhost:3000", defaultPriority: 1 })
|
|
244
233
|
.add("index", async (route) => ({ loc: routeToUrl(route) }))
|
|
245
234
|
.add("blog/detail", async (route) => [
|
|
246
|
-
{ loc: routeToUrl(route, {id: 1}), priority: 2 },
|
|
247
|
-
{ loc: routeToUrl(route, {id: 2}), priority: 2 },
|
|
235
|
+
{ loc: routeToUrl(route, { id: 1 }), priority: 2 },
|
|
236
|
+
{ loc: routeToUrl(route, { id: 2 }), priority: 2 },
|
|
248
237
|
])
|
|
249
238
|
.skip("admin/index")
|
|
250
239
|
.exhaustive();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/router",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.126.0",
|
|
4
4
|
"description": "UXF Router",
|
|
5
5
|
"author": "UXFans <dev@uxf.cz>",
|
|
6
6
|
"homepage": "https://gitlab.com/uxf-npm/router#readme",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"true-case-path": "2.2.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@uxf/core": "11.
|
|
29
|
+
"@uxf/core": "11.126.0",
|
|
30
30
|
"next": ">= 12",
|
|
31
31
|
"superstruct": "^2.0.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@uxf/core": "11.
|
|
34
|
+
"@uxf/core": "11.126.0",
|
|
35
35
|
"next": "16.3.0",
|
|
36
36
|
"superstruct": "^2.0.2"
|
|
37
37
|
}
|
package/sitemap-generator.d.ts
CHANGED
|
@@ -19,8 +19,8 @@ export type SitemapRouteResolvers<Locales extends string[], RouteList extends Ro
|
|
|
19
19
|
[K in keyof RouteList]: ((routeName: K) => Promise<RouteResolverResult>) | null;
|
|
20
20
|
};
|
|
21
21
|
export type SitemapGeneratorType = {
|
|
22
|
-
toXml()
|
|
23
|
-
toJson()
|
|
22
|
+
toXml: () => Promise<string>;
|
|
23
|
+
toJson: () => Promise<string>;
|
|
24
24
|
};
|
|
25
25
|
export type SitemapGeneratorOptions = {
|
|
26
26
|
baseUrl?: string;
|