@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.
Files changed (50) hide show
  1. package/README.md +13 -1
  2. package/package.json +1 -1
  3. package/{router.d.ts → router/router.d.ts} +9 -3
  4. package/{router.js → router/router.js} +2 -2
  5. package/router/routes-check/__test__/app/app-directory/[param]/page.d.ts +0 -0
  6. package/router/routes-check/__test__/app/app-directory/[param]/page.js +1 -0
  7. package/router/routes-check/__test__/app/app-directory/page.d.ts +0 -0
  8. package/router/routes-check/__test__/app/app-directory/page.js +1 -0
  9. package/router/routes-check/__test__/pages/index.d.ts +0 -0
  10. package/router/routes-check/__test__/pages/index.js +1 -0
  11. package/router/routes-check/__test__/pages/product/[id].d.ts +0 -0
  12. package/router/routes-check/__test__/pages/product/[id].js +1 -0
  13. package/router/routes-check/__test__/pages/product/edit.d.ts +0 -0
  14. package/router/routes-check/__test__/pages/product/edit.js +1 -0
  15. package/router/routes-check/__test__/pages/product/index.d.ts +0 -0
  16. package/router/routes-check/__test__/pages/product/index.js +1 -0
  17. package/router/routes-check/__test__/pages/product-2/[id]/index.d.ts +0 -0
  18. package/router/routes-check/__test__/pages/product-2/[id]/index.js +1 -0
  19. /package/{helper.d.ts → router/helper.d.ts} +0 -0
  20. /package/{helper.js → router/helper.js} +0 -0
  21. /package/{helper.test.d.ts → router/helper.test.d.ts} +0 -0
  22. /package/{helper.test.js → router/helper.test.js} +0 -0
  23. /package/{index.d.ts → router/index.d.ts} +0 -0
  24. /package/{index.js → router/index.js} +0 -0
  25. /package/{merge-route-matchers.d.ts → router/merge-route-matchers.d.ts} +0 -0
  26. /package/{merge-route-matchers.js → router/merge-route-matchers.js} +0 -0
  27. /package/{router.test.d.ts → router/router.test.d.ts} +0 -0
  28. /package/{router.test.js → router/router.test.js} +0 -0
  29. /package/{routes-check → router/routes-check}/routes-check.d.ts +0 -0
  30. /package/{routes-check → router/routes-check}/routes-check.js +0 -0
  31. /package/{routes-check → router/routes-check}/routes-check.test.d.ts +0 -0
  32. /package/{routes-check → router/routes-check}/routes-check.test.js +0 -0
  33. /package/{sitemap-generator.d.ts → router/sitemap-generator.d.ts} +0 -0
  34. /package/{sitemap-generator.js → router/sitemap-generator.js} +0 -0
  35. /package/{sitemap-generator.test.d.ts → router/sitemap-generator.test.d.ts} +0 -0
  36. /package/{sitemap-generator.test.js → router/sitemap-generator.test.js} +0 -0
  37. /package/{superstruct → router/superstruct}/array.d.ts +0 -0
  38. /package/{superstruct → router/superstruct}/array.js +0 -0
  39. /package/{superstruct → router/superstruct}/boolean.d.ts +0 -0
  40. /package/{superstruct → router/superstruct}/boolean.js +0 -0
  41. /package/{superstruct → router/superstruct}/index.d.ts +0 -0
  42. /package/{superstruct → router/superstruct}/index.js +0 -0
  43. /package/{superstruct → router/superstruct}/integer.d.ts +0 -0
  44. /package/{superstruct → router/superstruct}/integer.js +0 -0
  45. /package/{types.d.ts → router/types.d.ts} +0 -0
  46. /package/{types.js → router/types.js} +0 -0
  47. /package/{utils → router/utils}/object-to-xml.d.ts +0 -0
  48. /package/{utils → router/utils}/object-to-xml.js +0 -0
  49. /package/{utils → router/utils}/object-to-xml.test.d.ts +0 -0
  50. /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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/router",
3
- "version": "11.78.0",
3
+ "version": "11.80.2",
4
4
  "description": "UXF Router",
5
5
  "author": "UXFans <dev@uxf.cz>",
6
6
  "homepage": "https://gitlab.com/uxf-npm/router#readme",
@@ -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
- type ExtractSchema<T> = T extends {
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"]>>) => Promise<boolean>;
27
- replace: (params: Infer<NonNullable<RouteList[T]["schema"]>>) => Promise<boolean>;
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
  },
@@ -0,0 +1 @@
1
+ "use strict";
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ "use strict";
@@ -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