@uxf/router 11.78.0 → 11.80.2
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 +13 -1
- package/package.json +1 -1
- package/{router.d.ts → router/router.d.ts} +9 -3
- package/{router.js → router/router.js} +2 -2
- package/router/routes-check/__test__/app/app-directory/[param]/page.d.ts +0 -0
- package/router/routes-check/__test__/app/app-directory/[param]/page.js +1 -0
- package/router/routes-check/__test__/app/app-directory/page.d.ts +0 -0
- package/router/routes-check/__test__/app/app-directory/page.js +1 -0
- package/router/routes-check/__test__/pages/index.d.ts +0 -0
- package/router/routes-check/__test__/pages/index.js +1 -0
- package/router/routes-check/__test__/pages/product/[id].d.ts +0 -0
- package/router/routes-check/__test__/pages/product/[id].js +1 -0
- package/router/routes-check/__test__/pages/product/edit.d.ts +0 -0
- package/router/routes-check/__test__/pages/product/edit.js +1 -0
- package/router/routes-check/__test__/pages/product/index.d.ts +0 -0
- package/router/routes-check/__test__/pages/product/index.js +1 -0
- package/router/routes-check/__test__/pages/product-2/[id]/index.d.ts +0 -0
- package/router/routes-check/__test__/pages/product-2/[id]/index.js +1 -0
- /package/{helper.d.ts → router/helper.d.ts} +0 -0
- /package/{helper.js → router/helper.js} +0 -0
- /package/{helper.test.d.ts → router/helper.test.d.ts} +0 -0
- /package/{helper.test.js → router/helper.test.js} +0 -0
- /package/{index.d.ts → router/index.d.ts} +0 -0
- /package/{index.js → router/index.js} +0 -0
- /package/{merge-route-matchers.d.ts → router/merge-route-matchers.d.ts} +0 -0
- /package/{merge-route-matchers.js → router/merge-route-matchers.js} +0 -0
- /package/{router.test.d.ts → router/router.test.d.ts} +0 -0
- /package/{router.test.js → router/router.test.js} +0 -0
- /package/{routes-check → router/routes-check}/routes-check.d.ts +0 -0
- /package/{routes-check → router/routes-check}/routes-check.js +0 -0
- /package/{routes-check → router/routes-check}/routes-check.test.d.ts +0 -0
- /package/{routes-check → router/routes-check}/routes-check.test.js +0 -0
- /package/{sitemap-generator.d.ts → router/sitemap-generator.d.ts} +0 -0
- /package/{sitemap-generator.js → router/sitemap-generator.js} +0 -0
- /package/{sitemap-generator.test.d.ts → router/sitemap-generator.test.d.ts} +0 -0
- /package/{sitemap-generator.test.js → router/sitemap-generator.test.js} +0 -0
- /package/{superstruct → router/superstruct}/array.d.ts +0 -0
- /package/{superstruct → router/superstruct}/array.js +0 -0
- /package/{superstruct → router/superstruct}/boolean.d.ts +0 -0
- /package/{superstruct → router/superstruct}/boolean.js +0 -0
- /package/{superstruct → router/superstruct}/index.d.ts +0 -0
- /package/{superstruct → router/superstruct}/index.js +0 -0
- /package/{superstruct → router/superstruct}/integer.d.ts +0 -0
- /package/{superstruct → router/superstruct}/integer.js +0 -0
- /package/{types.d.ts → router/types.d.ts} +0 -0
- /package/{types.js → router/types.js} +0 -0
- /package/{utils → router/utils}/object-to-xml.d.ts +0 -0
- /package/{utils → router/utils}/object-to-xml.js +0 -0
- /package/{utils → router/utils}/object-to-xml.test.d.ts +0 -0
- /package/{utils → router/utils}/object-to-xml.test.js +0 -0
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ export default createRouter(
|
|
|
52
52
|
// routes/index.ts
|
|
53
53
|
|
|
54
54
|
import router from "./routes";
|
|
55
|
-
import { UxfGetServerSideProps, UxfGetStaticProps } from "@uxf/router";
|
|
55
|
+
import { UxfGetServerSideProps, UxfGetStaticProps, ExtractSchema } from "@uxf/router";
|
|
56
56
|
import { PreviewData as NextPreviewData } from "next/types";
|
|
57
57
|
|
|
58
58
|
export const {
|
|
@@ -62,6 +62,8 @@ export const {
|
|
|
62
62
|
useQueryParamsStatic
|
|
63
63
|
} = router;
|
|
64
64
|
|
|
65
|
+
export type GetRouteSchema<K extends keyof RouteList> = ExtractSchema<RouteList[K]>;
|
|
66
|
+
|
|
65
67
|
export type GetStaticProps<
|
|
66
68
|
Route extends keyof RouteList,
|
|
67
69
|
Props extends { [key: string]: any } = { [key: string]: any },
|
|
@@ -175,6 +177,16 @@ const routeMatcher = mergeRouteMatchers([
|
|
|
175
177
|
]);
|
|
176
178
|
```
|
|
177
179
|
|
|
180
|
+
## Type-safe route params
|
|
181
|
+
|
|
182
|
+
```tsx
|
|
183
|
+
import { GetRouteSchema } from "@app-routes";
|
|
184
|
+
|
|
185
|
+
const blogProps: GetRouteSchema<"blog/detail"> = {
|
|
186
|
+
id: 1,
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
178
190
|
## GetStaticProps
|
|
179
191
|
|
|
180
192
|
```tsx
|
package/package.json
CHANGED
|
@@ -3,7 +3,13 @@ import { NextRouter } from "next/router";
|
|
|
3
3
|
import { Infer, Struct } from "superstruct";
|
|
4
4
|
import { SitemapGeneratorOptions, SitemapGeneratorType, SitemapRouteResolvers } from "./sitemap-generator";
|
|
5
5
|
import { QueryParams, RoutesDefinition } from "./types";
|
|
6
|
-
|
|
6
|
+
interface TransitionOptions {
|
|
7
|
+
shallow?: boolean;
|
|
8
|
+
locale?: string | false;
|
|
9
|
+
scroll?: boolean;
|
|
10
|
+
unstable_skipClientCache?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export type ExtractSchema<T> = T extends {
|
|
7
13
|
schema: Struct<infer U, any>;
|
|
8
14
|
} ? U : null;
|
|
9
15
|
type Options = {
|
|
@@ -23,8 +29,8 @@ type RouteToUrlFunction<Locales extends string[], RouteList extends RoutesDefini
|
|
|
23
29
|
type QueryParamsResult<Nullable extends boolean, T extends keyof RouteList, Locales extends string[], RouteList extends RoutesDefinition<Locales>> = [
|
|
24
30
|
Nullable extends true ? Infer<NonNullable<RouteList[T]["schema"]>> | null : Infer<NonNullable<RouteList[T]["schema"]>>,
|
|
25
31
|
{
|
|
26
|
-
push: (params: Infer<NonNullable<RouteList[T]["schema"]
|
|
27
|
-
replace: (params: Infer<NonNullable<RouteList[T]["schema"]
|
|
32
|
+
push: (params: Infer<NonNullable<RouteList[T]["schema"]>>, options?: TransitionOptions) => Promise<boolean>;
|
|
33
|
+
replace: (params: Infer<NonNullable<RouteList[T]["schema"]>>, options?: TransitionOptions) => Promise<boolean>;
|
|
28
34
|
}
|
|
29
35
|
];
|
|
30
36
|
type SimplyNextRouter = Pick<NextRouter, "pathname" | "query" | "isReady">;
|
|
@@ -126,8 +126,8 @@ function createRouter(routes, routerOptions) {
|
|
|
126
126
|
return [
|
|
127
127
|
(0, superstruct_1.mask)(router.query, schema),
|
|
128
128
|
{
|
|
129
|
-
push: (params) => router.push(routeToUrl(routeName, params, {})),
|
|
130
|
-
replace: (params) => router.replace(routeToUrl(routeName, params, {})),
|
|
129
|
+
push: (params, options) => router.push(routeToUrl(routeName, params, {}), undefined, options),
|
|
130
|
+
replace: (params, options) => router.replace(routeToUrl(routeName, params, {}), undefined, options),
|
|
131
131
|
},
|
|
132
132
|
];
|
|
133
133
|
},
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|