@canonical/router-react 0.47.0 → 0.49.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 +3 -0
- package/dist/types/lib/Link/types.d.ts +14 -15
- package/dist/types/lib/Link/types.d.ts.map +1 -1
- package/dist/types/lib/Outlet/types.d.ts +7 -1
- package/dist/types/lib/Outlet/types.d.ts.map +1 -1
- package/dist/types/lib/RouterProvider/types.d.ts +7 -1
- package/dist/types/lib/RouterProvider/types.d.ts.map +1 -1
- package/dist/types/lib/register.d.ts +12 -1
- package/dist/types/lib/register.d.ts.map +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -104,10 +104,13 @@ All hooks and `Link` default to `RegisteredRouteMap`. Register your route map on
|
|
|
104
104
|
declare module "@canonical/router-react" {
|
|
105
105
|
interface RouterRegister {
|
|
106
106
|
routes: typeof routes;
|
|
107
|
+
meta: AppRouteMeta; // optional: types every route's `meta`
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
```
|
|
110
111
|
|
|
112
|
+
A declared `meta` is checked at each `route()` call and typed wherever a route is read (`router.routes[name].meta`, `match.route.meta`). Without it, `meta` is `Readonly<Record<string, unknown>>`.
|
|
113
|
+
|
|
111
114
|
Explicit generics (`<typeof routes>`) still work as an escape hatch for multi-router apps or library code.
|
|
112
115
|
|
|
113
116
|
Important distinction:
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import type { PathBuildOptions, RouteMap, RouteName, RouteOf } from "@canonical/router-core";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ComponentProps } from "react";
|
|
3
3
|
/**
|
|
4
|
-
* Props accepted by `Link`.
|
|
5
|
-
*
|
|
6
4
|
* The route-building half of these props is core's `PathBuildOptions`
|
|
7
5
|
* itself, not a structural duplicate of it: a copy would keep compiling
|
|
8
6
|
* against a stale contract (accepting, say, non-serializable `search`
|
|
9
7
|
* values) long after core tightened it.
|
|
10
8
|
*/
|
|
11
|
-
|
|
12
|
-
/** Content rendered inside the generated anchor element. */
|
|
13
|
-
readonly children?: ReactNode;
|
|
14
|
-
/** Trigger a file download instead of client-side navigation. */
|
|
15
|
-
readonly download?: AnchorHTMLAttributes<HTMLAnchorElement>["download"];
|
|
16
|
-
/** Optional click handler called before router interception runs. */
|
|
17
|
-
readonly onClick?: MouseEventHandler<HTMLAnchorElement>;
|
|
18
|
-
/** Optional hover handler called before router warming runs. */
|
|
19
|
-
readonly onMouseEnter?: MouseEventHandler<HTMLAnchorElement>;
|
|
20
|
-
/** Ref forwarded to the underlying anchor element. */
|
|
21
|
-
readonly ref?: Ref<HTMLAnchorElement>;
|
|
9
|
+
type OwnProps<TRoutes extends RouteMap, TName extends RouteName<TRoutes>> = {
|
|
22
10
|
/** The named route to navigate to. */
|
|
23
11
|
readonly to: TName;
|
|
24
|
-
}
|
|
12
|
+
} & PathBuildOptions<RouteOf<TRoutes, TName>>;
|
|
13
|
+
/**
|
|
14
|
+
* Props accepted by `Link`.
|
|
15
|
+
*
|
|
16
|
+
* `href` is excluded from the anchor's native props because it is derived
|
|
17
|
+
* from the chosen route rather than supplied by the caller. The own keys are
|
|
18
|
+
* listed literally rather than as `keyof OwnProps`: `PathBuildOptions` is a
|
|
19
|
+
* conditional mapped type, so `keyof` of it does not resolve while `TName` is
|
|
20
|
+
* still a type parameter.
|
|
21
|
+
*/
|
|
22
|
+
export type LinkProps<TRoutes extends RouteMap, TName extends RouteName<TRoutes>> = OwnProps<TRoutes, TName> & Omit<ComponentProps<"a">, "to" | "params" | "search" | "hash" | "replace" | "href">;
|
|
23
|
+
export {};
|
|
25
24
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/Link/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,QAAQ,EACR,SAAS,EACT,OAAO,EACR,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/Link/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,QAAQ,EACR,SAAS,EACT,OAAO,EACR,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAE5C;;;;;GAKG;AACH,KAAK,QAAQ,CAAC,OAAO,SAAS,QAAQ,EAAE,KAAK,SAAS,SAAS,CAAC,OAAO,CAAC,IAAI;IAC1E,sCAAsC;IACtC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;CACpB,GAAG,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AAE9C;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,CACnB,OAAO,SAAS,QAAQ,EACxB,KAAK,SAAS,SAAS,CAAC,OAAO,CAAC,IAC9B,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,GAC1B,IAAI,CACF,cAAc,CAAC,GAAG,CAAC,EACnB,IAAI,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CACzD,CAAC"}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Props accepted by `Outlet`.
|
|
4
|
+
*
|
|
5
|
+
* Exempt from the native-prop extension convention: `Outlet` renders a
|
|
6
|
+
* `Suspense` around whatever route content matches, so it has no root tag
|
|
7
|
+
* whose native props these could extend.
|
|
8
|
+
*/
|
|
3
9
|
export interface OutletProps {
|
|
4
10
|
/** Content shown while suspended route output is pending. */
|
|
5
11
|
readonly fallback?: ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/Outlet/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/Outlet/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,6DAA6D;IAC7D,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;CAC/B"}
|
|
@@ -2,7 +2,13 @@ import type { AnyRoute, RouteMap, Router } from "@canonical/router-core";
|
|
|
2
2
|
import type { ReactNode } from "react";
|
|
3
3
|
/** A router instance widened to the fully dynamic React binding shape. */
|
|
4
4
|
export type AnyReactRouter = Router<RouteMap, AnyRoute | undefined>;
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Props accepted by `RouterProvider`.
|
|
7
|
+
*
|
|
8
|
+
* Exempt from the native-prop extension convention: `RouterProvider` renders
|
|
9
|
+
* a context provider and no DOM element, so it has no root tag whose native
|
|
10
|
+
* props these could extend.
|
|
11
|
+
*/
|
|
6
12
|
export interface RouterProviderProps<TRoutes extends RouteMap, TNotFound extends AnyRoute | undefined = undefined> {
|
|
7
13
|
/** React children that should be able to consume the router. */
|
|
8
14
|
readonly children?: ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/RouterProvider/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,0EAA0E;AAC1E,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC;AAEpE
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/RouterProvider/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,0EAA0E;AAC1E,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB,CAClC,OAAO,SAAS,QAAQ,EACxB,SAAS,SAAS,QAAQ,GAAG,SAAS,GAAG,SAAS;IAElD,gEAAgE;IAChE,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAC9B,yDAAyD;IACzD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;CAC7C"}
|
|
@@ -9,15 +9,25 @@ import type { AnyRoute, RouteMap } from "@canonical/router-core";
|
|
|
9
9
|
* declare module "@canonical/router-react" {
|
|
10
10
|
* interface RouterRegister {
|
|
11
11
|
* routes: typeof appRoutes;
|
|
12
|
+
* meta: AppRouteMeta;
|
|
12
13
|
* }
|
|
13
14
|
* }
|
|
14
15
|
* ```
|
|
15
16
|
*
|
|
16
17
|
* When no registration exists the fallback is `RouteMap` (any string key),
|
|
17
|
-
* which compiles but provides no autocomplete or typo detection.
|
|
18
|
+
* which compiles but provides no autocomplete or typo detection. A declared
|
|
19
|
+
* `meta` types every route's `meta` (see `RouteMeta` in
|
|
20
|
+
* `@canonical/router-core`).
|
|
18
21
|
*/
|
|
19
22
|
export interface RouterRegister {
|
|
20
23
|
}
|
|
24
|
+
/** This package's register, under a name the core augmentation can extend. */
|
|
25
|
+
type ReactRouterRegister = RouterRegister;
|
|
26
|
+
declare module "@canonical/router-core" {
|
|
27
|
+
/** Merges `@canonical/router-react`'s register into the core one. */
|
|
28
|
+
interface RouterRegister extends ReactRouterRegister {
|
|
29
|
+
}
|
|
30
|
+
}
|
|
21
31
|
/** Resolves to the registered route map, or falls back to `RouteMap`. */
|
|
22
32
|
export type RegisteredRouteMap = RouterRegister extends {
|
|
23
33
|
routes: infer T extends RouteMap;
|
|
@@ -26,4 +36,5 @@ export type RegisteredRouteMap = RouterRegister extends {
|
|
|
26
36
|
export type RegisteredNotFound = RouterRegister extends {
|
|
27
37
|
notFound: infer T extends AnyRoute | undefined;
|
|
28
38
|
} ? T : undefined;
|
|
39
|
+
export {};
|
|
29
40
|
//# sourceMappingURL=register.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../src/lib/register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEjE
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../src/lib/register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,WAAW,cAAc;CAAG;AAElC,8EAA8E;AAC9E,KAAK,mBAAmB,GAAG,cAAc,CAAC;AAE1C,OAAO,QAAQ,wBAAwB,CAAC;IACtC,qEAAqE;IACrE,UAAU,cAAe,SAAQ,mBAAmB;KAAG;CACxD;AAED,yEAAyE;AACzE,MAAM,MAAM,kBAAkB,GAAG,cAAc,SAAS;IACtD,MAAM,EAAE,MAAM,CAAC,SAAS,QAAQ,CAAC;CAClC,GACG,CAAC,GACD,QAAQ,CAAC;AAEb,gFAAgF;AAChF,MAAM,MAAM,kBAAkB,GAAG,cAAc,SAAS;IACtD,QAAQ,EAAE,MAAM,CAAC,SAAS,QAAQ,GAAG,SAAS,CAAC;CAChD,GACG,CAAC,GACD,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonical/router-react",
|
|
3
3
|
"description": "React bindings for @canonical/router-core",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.49.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/types/index.d.ts",
|
|
@@ -44,17 +44,17 @@
|
|
|
44
44
|
"test:coverage": "vitest run --coverage"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@canonical/react-ssr": "^0.
|
|
48
|
-
"@canonical/router-core": "^0.
|
|
47
|
+
"@canonical/react-ssr": "^0.49.0",
|
|
48
|
+
"@canonical/router-core": "^0.49.0",
|
|
49
49
|
"react": "^19.2.4",
|
|
50
50
|
"react-dom": "^19.2.4"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@biomejs/biome": "2.
|
|
54
|
-
"@canonical/biome-config": "0.
|
|
55
|
-
"@canonical/typescript-config-react": "^0.
|
|
56
|
-
"@canonical/vitest-config-react": "^0.
|
|
57
|
-
"@canonical/webarchitect": "0.
|
|
53
|
+
"@biomejs/biome": "2.6.9",
|
|
54
|
+
"@canonical/biome-config": "0.47.0",
|
|
55
|
+
"@canonical/typescript-config-react": "^0.49.0",
|
|
56
|
+
"@canonical/vitest-config-react": "^0.49.0",
|
|
57
|
+
"@canonical/webarchitect": "0.46.0",
|
|
58
58
|
"@testing-library/jest-dom": "^7.0.0",
|
|
59
59
|
"@testing-library/react": "^16.3.2",
|
|
60
60
|
"@types/node": "^26.0.0",
|
|
@@ -62,10 +62,10 @@
|
|
|
62
62
|
"@types/react-dom": "^19.2.3",
|
|
63
63
|
"@vitejs/plugin-react": "^6.0.0",
|
|
64
64
|
"@vitest/coverage-v8": "^5.0.0",
|
|
65
|
-
"jsdom": "^
|
|
65
|
+
"jsdom": "^31.0.0",
|
|
66
66
|
"typescript": "^7.0.2",
|
|
67
67
|
"vite": "^8.0.1",
|
|
68
68
|
"vitest": "^5.0.0"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "9b71099ded16351ee14432246e3d8190f48767ed"
|
|
71
71
|
}
|