@molecule/app-routing-react-router 1.1.3 → 1.2.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 +208 -118
- package/dist/dom.d.ts +50 -0
- package/dist/dom.d.ts.map +1 -0
- package/dist/dom.js +37 -0
- package/dist/dom.js.map +1 -0
- package/dist/hooks.d.ts +42 -9
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +110 -14
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +25 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -7
- package/dist/index.js.map +1 -1
- package/dist/lazyPage.d.ts +57 -0
- package/dist/lazyPage.d.ts.map +1 -0
- package/dist/lazyPage.js +62 -0
- package/dist/lazyPage.js.map +1 -0
- package/dist/routers.d.ts +102 -0
- package/dist/routers.d.ts.map +1 -0
- package/dist/routers.js +86 -0
- package/dist/routers.js.map +1 -0
- package/package.json +27 -2
package/dist/hooks.js
CHANGED
|
@@ -4,8 +4,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
-
import { createContext, useContext, useEffect, useMemo } from 'react';
|
|
8
|
-
import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router';
|
|
7
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from 'react';
|
|
8
|
+
import { useInRouterContext, useLocation, useNavigate, useParams, useSearchParams, } from 'react-router';
|
|
9
9
|
import { t } from '@molecule/app-i18n';
|
|
10
10
|
import { setRouter } from '@molecule/app-routing';
|
|
11
11
|
import { createReactRouter } from './provider.js';
|
|
@@ -20,7 +20,8 @@ const MoleculeRouterContext = createContext(null);
|
|
|
20
20
|
* Bonding happens in an effect on mount (and again whenever the location/params
|
|
21
21
|
* change), so `@molecule/app-routing`'s `navigate()`/`getRouter()` drive THIS real
|
|
22
22
|
* React Router adapter — no manual `setRouter` wiring required. Mount it once inside
|
|
23
|
-
*
|
|
23
|
+
* any React Router router when non-React code needs the bond, named routes are
|
|
24
|
+
* configured, or `onRouterReady` is needed. The routing hooks work without this provider.
|
|
24
25
|
*
|
|
25
26
|
* @param props - The provider props (see {@link MoleculeRouterProviderProps}):
|
|
26
27
|
* `children` (rendered inside the router context), `routes` (optional named-route
|
|
@@ -30,8 +31,8 @@ const MoleculeRouterContext = createContext(null);
|
|
|
30
31
|
* @returns The rendered provider wrapping children with the router context.
|
|
31
32
|
* @example
|
|
32
33
|
* ```tsx
|
|
33
|
-
* import {
|
|
34
|
-
* import { MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
34
|
+
* import { Routes, Route } from 'react-router'
|
|
35
|
+
* import { BrowserRouter, MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
35
36
|
*
|
|
36
37
|
* function App() {
|
|
37
38
|
* // Bonds automatically — molecule packages' navigate() now drive React Router.
|
|
@@ -75,10 +76,17 @@ export function MoleculeRouterProvider(props) {
|
|
|
75
76
|
return _jsx(MoleculeRouterContext.Provider, { value: router, children: children });
|
|
76
77
|
}
|
|
77
78
|
/**
|
|
78
|
-
* Hook to get the molecule Router
|
|
79
|
+
* Hook to get the molecule Router inside any React Router router, including
|
|
80
|
+
* BrowserRouter, HashRouter, MemoryRouter, Router, or RouterProvider from this
|
|
81
|
+
* package or React Router itself. No MoleculeRouterProvider is required.
|
|
82
|
+
*
|
|
83
|
+
* When MoleculeRouterProvider is mounted, returns its exact router with its named
|
|
84
|
+
* routes. Otherwise creates a local adapter from React Router's hooks without
|
|
85
|
+
* bonding it globally. Mount MoleculeRouterProvider for the non-React
|
|
86
|
+
* `@molecule/app-routing` navigate()/getRouter() bond or onRouterReady.
|
|
79
87
|
*
|
|
80
88
|
* @returns The molecule Router instance
|
|
81
|
-
* @throws {Error} If used outside
|
|
89
|
+
* @throws {Error} If used outside a React Router router; mount a router component.
|
|
82
90
|
*
|
|
83
91
|
* @example
|
|
84
92
|
* ```tsx
|
|
@@ -95,15 +103,23 @@ export function MoleculeRouterProvider(props) {
|
|
|
95
103
|
*/
|
|
96
104
|
export function useMoleculeRouter() {
|
|
97
105
|
const router = useContext(MoleculeRouterContext);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
const inRouter = useInRouterContext();
|
|
107
|
+
if (!inRouter) {
|
|
108
|
+
throw new Error(t('routing.error.useMoleculeRouterOutsideRouter', undefined, {
|
|
109
|
+
defaultValue: 'useMoleculeRouter must be used within a React Router router. Mount BrowserRouter, HashRouter, MemoryRouter, Router, or RouterProvider.',
|
|
101
110
|
}));
|
|
102
111
|
}
|
|
103
|
-
|
|
112
|
+
// Always call the React Router hooks, including when the provider supplies the
|
|
113
|
+
// adapter. The guard above throws only for an invalid render outside any router.
|
|
114
|
+
const navigate = useNavigate();
|
|
115
|
+
const location = useLocation();
|
|
116
|
+
const params = useParams();
|
|
117
|
+
return useMemo(() => router ?? createReactRouter({ navigate, location, params }), [router, navigate, location, params]);
|
|
104
118
|
}
|
|
105
119
|
/**
|
|
106
|
-
* Hook to check if a path is currently active.
|
|
120
|
+
* Hook to check if a path is currently active inside any React Router router.
|
|
121
|
+
* MoleculeRouterProvider is optional; mount it only for named routes, the
|
|
122
|
+
* non-React navigate()/getRouter() bond, or onRouterReady.
|
|
107
123
|
*
|
|
108
124
|
* @param path - Path to check
|
|
109
125
|
* @param exact - Whether to require exact match
|
|
@@ -128,7 +144,9 @@ export function useIsActive(path, exact) {
|
|
|
128
144
|
return useMemo(() => router.isActive(path, exact), [router, path, exact, location.pathname]);
|
|
129
145
|
}
|
|
130
146
|
/**
|
|
131
|
-
* Hook to get a navigate function with molecule Router options
|
|
147
|
+
* Hook to get a navigate function with molecule Router options inside any React
|
|
148
|
+
* Router router. MoleculeRouterProvider is optional; mount it only for named
|
|
149
|
+
* routes, the non-React navigate()/getRouter() bond, or onRouterReady.
|
|
132
150
|
*
|
|
133
151
|
* @returns Navigate function
|
|
134
152
|
*
|
|
@@ -149,7 +167,9 @@ export function useMoleculeNavigate() {
|
|
|
149
167
|
return router.navigate.bind(router);
|
|
150
168
|
}
|
|
151
169
|
/**
|
|
152
|
-
* Hook to get current query params as an object.
|
|
170
|
+
* Hook to get current query params as an object inside any React Router router.
|
|
171
|
+
* MoleculeRouterProvider is optional; mount it only for named routes, the
|
|
172
|
+
* non-React navigate()/getRouter() bond, or onRouterReady.
|
|
153
173
|
*
|
|
154
174
|
* @returns Query params object
|
|
155
175
|
*
|
|
@@ -167,4 +187,80 @@ export function useMoleculeQuery() {
|
|
|
167
187
|
// Re-evaluate when search changes
|
|
168
188
|
return useMemo(() => router.getQuery(), [router, location.search]);
|
|
169
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Consume a credential query parameter into component state and remove only that parameter from
|
|
192
|
+
* the address through React Router. The value survives local rerenders, StrictMode, failed-submit
|
|
193
|
+
* retries and later query-only navigation; a newly arriving value on the same mounted route is
|
|
194
|
+
* consumed too. Path, hash, unrelated query values and router location state are retained.
|
|
195
|
+
*
|
|
196
|
+
* React Router owns the URL replacement, so `useLocation()` and `window.location` agree. A
|
|
197
|
+
* metadata-only history merge retains unrelated pre-existing top-level state fields that React
|
|
198
|
+
* Router does not model; it never changes the URL or the router's `usr`/`key`/`idx` fields.
|
|
199
|
+
*
|
|
200
|
+
* @param name - The credential query key to consume, for example `token` or `code`.
|
|
201
|
+
* @returns The consumed value and its state setter; the value is empty before first consumption.
|
|
202
|
+
* @example
|
|
203
|
+
* ```tsx
|
|
204
|
+
* const [resetToken] = useConsumedSearchParam('token')
|
|
205
|
+
* // The form submits resetToken after the address no longer contains it.
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export function useConsumedSearchParam(name) {
|
|
209
|
+
const location = useLocation();
|
|
210
|
+
const navigate = useNavigate();
|
|
211
|
+
const current = new URLSearchParams(location.search).get(name) ?? '';
|
|
212
|
+
const [consumed, setConsumed] = useState(current);
|
|
213
|
+
const consumedByEntry = useRef(new Map());
|
|
214
|
+
const pending = useRef(undefined);
|
|
215
|
+
const latest = useRef(consumed);
|
|
216
|
+
latest.current = consumed;
|
|
217
|
+
const updateConsumed = useCallback((action) => {
|
|
218
|
+
setConsumed((previous) => {
|
|
219
|
+
const next = typeof action === 'function' ? action(previous) : action;
|
|
220
|
+
consumedByEntry.current.set(location.key, next);
|
|
221
|
+
return next;
|
|
222
|
+
});
|
|
223
|
+
}, [location.key]);
|
|
224
|
+
useEffect(() => {
|
|
225
|
+
const params = new URLSearchParams(location.search);
|
|
226
|
+
if (!params.has(name)) {
|
|
227
|
+
const pendingValue = pending.current;
|
|
228
|
+
if (pendingValue !== undefined) {
|
|
229
|
+
consumedByEntry.current.set(location.key, pendingValue);
|
|
230
|
+
pending.current = undefined;
|
|
231
|
+
}
|
|
232
|
+
else if (consumedByEntry.current.has(location.key)) {
|
|
233
|
+
setConsumed(consumedByEntry.current.get(location.key) ?? '');
|
|
234
|
+
}
|
|
235
|
+
else if (latest.current) {
|
|
236
|
+
// Query-only navigation creates a new key but not a new credential link.
|
|
237
|
+
consumedByEntry.current.set(location.key, latest.current);
|
|
238
|
+
}
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const value = params.get(name) ?? '';
|
|
242
|
+
pending.current = value;
|
|
243
|
+
setConsumed(value);
|
|
244
|
+
params.delete(name);
|
|
245
|
+
const search = params.toString();
|
|
246
|
+
const previousHistoryState = typeof window === 'undefined' ? undefined : window.history.state;
|
|
247
|
+
navigate({
|
|
248
|
+
pathname: location.pathname,
|
|
249
|
+
search: search ? `?${search}` : '',
|
|
250
|
+
hash: location.hash,
|
|
251
|
+
}, { replace: true, state: location.state });
|
|
252
|
+
if (previousHistoryState !== null &&
|
|
253
|
+
typeof previousHistoryState === 'object' &&
|
|
254
|
+
typeof window !== 'undefined') {
|
|
255
|
+
const retained = Object.fromEntries(Object.entries(previousHistoryState).filter(([key]) => !['usr', 'key', 'idx', 'masked'].includes(key)));
|
|
256
|
+
if (Object.keys(retained).length > 0) {
|
|
257
|
+
window.history.replaceState({ ...retained, ...window.history.state }, '', window.location.href);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}, [location, navigate, name]);
|
|
261
|
+
return [
|
|
262
|
+
current || (consumedByEntry.current.get(location.key) ?? consumed),
|
|
263
|
+
updateConsumed,
|
|
264
|
+
];
|
|
265
|
+
}
|
|
170
266
|
//# sourceMappingURL=hooks.js.map
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":";AAAA;;;;GAIG;AAEH,OAAc,
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":";AAAA;;;;GAIG;AAEH,OAAc,EACZ,aAAa,EAIb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAA;AACd,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,SAAS,EACT,eAAe,GAChB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAGjD;;GAEG;AACH,MAAM,qBAAqB,GAAG,aAAa,CAAgB,IAAI,CAAC,CAAA;AAsBhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAkC;IACvE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,EAAE,EAAE,aAAa,EAAE,GAAG,KAAK,CAAA;IACtD,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAA;IAC9B,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAA;IAC9B,MAAM,MAAM,GAAG,SAAS,EAA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AAO,CAAC,oBAAoB,CAAC,CAAC,MAAM,CACzC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAC1D,CACF,CAAA;YACD,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrC,MAAM,CAAC,OAAO,CAAC,YAAY,CACzB,EAAE,GAAG,QAAQ,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EACxC,EAAE,EACF,MAAM,CAAC,QAAQ,CAAC,IAAI,CACrB,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAA;IAE9B,OAAO;QACL,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC;QAClE,cAAc;KACN,CAAA;AACZ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
* This package provides a React Router implementation of the molecule Router interface,
|
|
5
5
|
* allowing you to use molecule's routing abstractions with React Router.
|
|
6
6
|
*
|
|
7
|
+
* `useMoleculeRouter`, `useMoleculeQuery`, `useMoleculeNavigate`, and `useIsActive`
|
|
8
|
+
* work inside any React Router router (BrowserRouter, HashRouter, MemoryRouter,
|
|
9
|
+
* Router, or RouterProvider), from this package or React Router itself. No
|
|
10
|
+
* MoleculeRouterProvider is required for these hooks. Mount MoleculeRouterProvider
|
|
11
|
+
* only to bond the adapter for non-React `@molecule/app-routing` navigate()/getRouter(),
|
|
12
|
+
* supply named routes, or receive onRouterReady. Hook-created adapters remain local
|
|
13
|
+
* so multiple consumers cannot overwrite the global router bond.
|
|
14
|
+
*
|
|
7
15
|
* **Paginated or filtered page? Use `useListRoute` for its URL state.** It reads
|
|
8
16
|
* page, filters and selected views from the current URL; builds links that retain
|
|
9
17
|
* the current path/filters; and resets page when a filter or view changes. Declare
|
|
@@ -12,10 +20,11 @@
|
|
|
12
20
|
*
|
|
13
21
|
* @example
|
|
14
22
|
* ```tsx
|
|
15
|
-
* import {
|
|
16
|
-
* import { MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
23
|
+
* import { Routes, Route } from 'react-router'
|
|
24
|
+
* import { BrowserRouter, MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
17
25
|
*
|
|
18
26
|
* function App() {
|
|
27
|
+
* // Optional: include this provider for non-React navigation or named routes.
|
|
19
28
|
* // MoleculeRouterProvider bonds the adapter automatically (calls setRouter in an
|
|
20
29
|
* // effect on mount), so @molecule/app-routing's navigate()/getRouter() drive THIS
|
|
21
30
|
* // real React Router — no manual setRouter wiring needed.
|
|
@@ -135,17 +144,26 @@
|
|
|
135
144
|
* - **Do NOT wire the exported `provider` const** in a React Router app — it is a
|
|
136
145
|
* no-hooks fallback (empty params, `window.location.href` navigation). Use
|
|
137
146
|
* `MoleculeRouterProvider` (or `createReactRouter` with hook values) instead.
|
|
138
|
-
* - The provider must live INSIDE
|
|
139
|
-
* - **Import from
|
|
140
|
-
*
|
|
141
|
-
* (`
|
|
147
|
+
* - The provider must live INSIDE a React Router router (it calls React Router hooks).
|
|
148
|
+
* - **Import router components from this bond, never directly from React Router.**
|
|
149
|
+
* Its wrappers turn transitions off, so a navigation renders the new route in the
|
|
150
|
+
* same commit as the URL change. Import non-router APIs (`Routes`, `Route`, `Link`,
|
|
151
|
+
* hooks) from `'react-router'`. A DOM data router's `RouterProvider` and the
|
|
152
|
+
* framework-mode `HydratedRouter` come from `@molecule/app-routing-react-router/dom`.
|
|
153
|
+
* - **Declare pages loaded on demand with `lazyPage`, not `React.lazy`.** Each page then
|
|
154
|
+
* has a Suspense boundary of its own, so navigating to a page whose code is still
|
|
155
|
+
* loading removes the previous page at once. Under one shared `<Suspense>` around
|
|
156
|
+
* `<Routes>`, React keeps the previous page mounted (hidden) until the new code
|
|
157
|
+
* arrives, while the URL already names the new page.
|
|
142
158
|
*
|
|
143
159
|
* @module @molecule/app-routing-react-router
|
|
144
160
|
*/
|
|
145
161
|
export * from './hooks.js';
|
|
162
|
+
export * from './lazyPage.js';
|
|
146
163
|
export * from './list-types.js';
|
|
147
164
|
export * from './provider.js';
|
|
148
|
-
export * from './
|
|
165
|
+
export * from './routers.js';
|
|
166
|
+
export type { GuardResult, NavigateOptions, NavigationGuard, QueryParams, ReactRouterConfig, ReactRouterHooks, RouteChangeListener, RouteDefinition, RouteLocation, RouteMatch, RouteParams, RouterConfig, } from './types.js';
|
|
149
167
|
export * from './useListRoute.js';
|
|
150
168
|
export * from './utilities.js';
|
|
151
169
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+JG;AAEH,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,YAAY,EACV,WAAW,EACX,eAAe,EACf,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,UAAU,EACV,WAAW,EACX,YAAY,GACb,MAAM,YAAY,CAAA;AACnB,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
* This package provides a React Router implementation of the molecule Router interface,
|
|
5
5
|
* allowing you to use molecule's routing abstractions with React Router.
|
|
6
6
|
*
|
|
7
|
+
* `useMoleculeRouter`, `useMoleculeQuery`, `useMoleculeNavigate`, and `useIsActive`
|
|
8
|
+
* work inside any React Router router (BrowserRouter, HashRouter, MemoryRouter,
|
|
9
|
+
* Router, or RouterProvider), from this package or React Router itself. No
|
|
10
|
+
* MoleculeRouterProvider is required for these hooks. Mount MoleculeRouterProvider
|
|
11
|
+
* only to bond the adapter for non-React `@molecule/app-routing` navigate()/getRouter(),
|
|
12
|
+
* supply named routes, or receive onRouterReady. Hook-created adapters remain local
|
|
13
|
+
* so multiple consumers cannot overwrite the global router bond.
|
|
14
|
+
*
|
|
7
15
|
* **Paginated or filtered page? Use `useListRoute` for its URL state.** It reads
|
|
8
16
|
* page, filters and selected views from the current URL; builds links that retain
|
|
9
17
|
* the current path/filters; and resets page when a filter or view changes. Declare
|
|
@@ -12,10 +20,11 @@
|
|
|
12
20
|
*
|
|
13
21
|
* @example
|
|
14
22
|
* ```tsx
|
|
15
|
-
* import {
|
|
16
|
-
* import { MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
23
|
+
* import { Routes, Route } from 'react-router'
|
|
24
|
+
* import { BrowserRouter, MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
17
25
|
*
|
|
18
26
|
* function App() {
|
|
27
|
+
* // Optional: include this provider for non-React navigation or named routes.
|
|
19
28
|
* // MoleculeRouterProvider bonds the adapter automatically (calls setRouter in an
|
|
20
29
|
* // effect on mount), so @molecule/app-routing's navigate()/getRouter() drive THIS
|
|
21
30
|
* // real React Router — no manual setRouter wiring needed.
|
|
@@ -135,17 +144,25 @@
|
|
|
135
144
|
* - **Do NOT wire the exported `provider` const** in a React Router app — it is a
|
|
136
145
|
* no-hooks fallback (empty params, `window.location.href` navigation). Use
|
|
137
146
|
* `MoleculeRouterProvider` (or `createReactRouter` with hook values) instead.
|
|
138
|
-
* - The provider must live INSIDE
|
|
139
|
-
* - **Import from
|
|
140
|
-
*
|
|
141
|
-
* (`
|
|
147
|
+
* - The provider must live INSIDE a React Router router (it calls React Router hooks).
|
|
148
|
+
* - **Import router components from this bond, never directly from React Router.**
|
|
149
|
+
* Its wrappers turn transitions off, so a navigation renders the new route in the
|
|
150
|
+
* same commit as the URL change. Import non-router APIs (`Routes`, `Route`, `Link`,
|
|
151
|
+
* hooks) from `'react-router'`. A DOM data router's `RouterProvider` and the
|
|
152
|
+
* framework-mode `HydratedRouter` come from `@molecule/app-routing-react-router/dom`.
|
|
153
|
+
* - **Declare pages loaded on demand with `lazyPage`, not `React.lazy`.** Each page then
|
|
154
|
+
* has a Suspense boundary of its own, so navigating to a page whose code is still
|
|
155
|
+
* loading removes the previous page at once. Under one shared `<Suspense>` around
|
|
156
|
+
* `<Routes>`, React keeps the previous page mounted (hidden) until the new code
|
|
157
|
+
* arrives, while the URL already names the new page.
|
|
142
158
|
*
|
|
143
159
|
* @module @molecule/app-routing-react-router
|
|
144
160
|
*/
|
|
145
161
|
export * from './hooks.js';
|
|
162
|
+
export * from './lazyPage.js';
|
|
146
163
|
export * from './list-types.js';
|
|
147
164
|
export * from './provider.js';
|
|
148
|
-
export * from './
|
|
165
|
+
export * from './routers.js';
|
|
149
166
|
export * from './useListRoute.js';
|
|
150
167
|
export * from './utilities.js';
|
|
151
168
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+JG;AAEH,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAe5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route pages loaded on demand, each inside a Suspense boundary of its own.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { type ComponentProps, type ComponentType, lazy, type ReactNode } from 'react';
|
|
7
|
+
/** Any component `React.lazy` can load. */
|
|
8
|
+
export type LazyLoadableComponent = Awaited<ReturnType<Parameters<typeof lazy>[0]>>['default'];
|
|
9
|
+
/** Options for {@link lazyPage}. */
|
|
10
|
+
export interface LazyPageOptions {
|
|
11
|
+
/** What the page's area shows while its code loads. Defaults to nothing. */
|
|
12
|
+
fallback?: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Load a route's page on demand, inside a Suspense boundary that belongs to the page.
|
|
16
|
+
*
|
|
17
|
+
* Use it instead of `React.lazy` for every page a `<Route>` renders. Navigating to a
|
|
18
|
+
* page whose code has not loaded yet then replaces the previous page at once: the
|
|
19
|
+
* previous page unmounts and the new page's own boundary shows `fallback` until its
|
|
20
|
+
* code arrives. With `React.lazy` under one shared `<Suspense>` around `<Routes>`,
|
|
21
|
+
* React keeps the previous page mounted (hidden) behind that boundary's fallback, so
|
|
22
|
+
* the URL already names the new page while the old page's content is still in the
|
|
23
|
+
* DOM, and a check such as `getByRole('heading')` finds the old page's headings.
|
|
24
|
+
* Layout routes (an app shell around `<Outlet />`) stay mounted either way.
|
|
25
|
+
*
|
|
26
|
+
* @param load - Loads the page module, as for `React.lazy`:
|
|
27
|
+
* `() => import('./pages/Article.js').then((m) => ({ default: m.Article }))`.
|
|
28
|
+
* @param options - Optional `fallback` shown in the page's area while its code loads.
|
|
29
|
+
* @returns A component to use as a route's element: `<Route path="/article/:slug" element={<Article />} />`.
|
|
30
|
+
* Its props are the page's own, without the `undefined` an optional props parameter
|
|
31
|
+
* (`function Draft({ initial }: DraftProps = {})`) adds: a component type carrying it is
|
|
32
|
+
* not a valid JSX element type wherever React's types resolve from a second copy.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* import { Route, Routes } from 'react-router'
|
|
37
|
+
* import { BrowserRouter, lazyPage } from '@molecule/app-routing-react-router'
|
|
38
|
+
*
|
|
39
|
+
* const Home = lazyPage(() => import('./pages/Home.js').then((m) => ({ default: m.Home })))
|
|
40
|
+
* const Article = lazyPage(() =>
|
|
41
|
+
* import('./pages/Article.js').then((m) => ({ default: m.Article })),
|
|
42
|
+
* )
|
|
43
|
+
*
|
|
44
|
+
* const app = (
|
|
45
|
+
* <BrowserRouter>
|
|
46
|
+
* <Routes>
|
|
47
|
+
* <Route path="/" element={<Home />} />
|
|
48
|
+
* <Route path="/article/:slug" element={<Article />} />
|
|
49
|
+
* </Routes>
|
|
50
|
+
* </BrowserRouter>
|
|
51
|
+
* )
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function lazyPage<Page extends LazyLoadableComponent>(load: () => Promise<{
|
|
55
|
+
default: Page;
|
|
56
|
+
}>, options?: LazyPageOptions): ComponentType<NonNullable<ComponentProps<Page>>>;
|
|
57
|
+
//# sourceMappingURL=lazyPage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazyPage.d.ts","sourceRoot":"","sources":["../src/lazyPage.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,aAAa,EAElB,IAAI,EACJ,KAAK,SAAS,EAEf,MAAM,OAAO,CAAA;AAEd,2CAA2C;AAC3C,MAAM,MAAM,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;AAE9F,oCAAoC;AACpC,MAAM,WAAW,eAAe;IAC9B,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,QAAQ,CAAC,IAAI,SAAS,qBAAqB,EACzD,IAAI,EAAE,MAAM,OAAO,CAAC;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,CAAC,EACtC,OAAO,GAAE,eAAoB,GAC5B,aAAa,CAAC,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAiBlD"}
|
package/dist/lazyPage.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Route pages loaded on demand, each inside a Suspense boundary of its own.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { lazy, Suspense, } from 'react';
|
|
8
|
+
/**
|
|
9
|
+
* Load a route's page on demand, inside a Suspense boundary that belongs to the page.
|
|
10
|
+
*
|
|
11
|
+
* Use it instead of `React.lazy` for every page a `<Route>` renders. Navigating to a
|
|
12
|
+
* page whose code has not loaded yet then replaces the previous page at once: the
|
|
13
|
+
* previous page unmounts and the new page's own boundary shows `fallback` until its
|
|
14
|
+
* code arrives. With `React.lazy` under one shared `<Suspense>` around `<Routes>`,
|
|
15
|
+
* React keeps the previous page mounted (hidden) behind that boundary's fallback, so
|
|
16
|
+
* the URL already names the new page while the old page's content is still in the
|
|
17
|
+
* DOM, and a check such as `getByRole('heading')` finds the old page's headings.
|
|
18
|
+
* Layout routes (an app shell around `<Outlet />`) stay mounted either way.
|
|
19
|
+
*
|
|
20
|
+
* @param load - Loads the page module, as for `React.lazy`:
|
|
21
|
+
* `() => import('./pages/Article.js').then((m) => ({ default: m.Article }))`.
|
|
22
|
+
* @param options - Optional `fallback` shown in the page's area while its code loads.
|
|
23
|
+
* @returns A component to use as a route's element: `<Route path="/article/:slug" element={<Article />} />`.
|
|
24
|
+
* Its props are the page's own, without the `undefined` an optional props parameter
|
|
25
|
+
* (`function Draft({ initial }: DraftProps = {})`) adds: a component type carrying it is
|
|
26
|
+
* not a valid JSX element type wherever React's types resolve from a second copy.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* import { Route, Routes } from 'react-router'
|
|
31
|
+
* import { BrowserRouter, lazyPage } from '@molecule/app-routing-react-router'
|
|
32
|
+
*
|
|
33
|
+
* const Home = lazyPage(() => import('./pages/Home.js').then((m) => ({ default: m.Home })))
|
|
34
|
+
* const Article = lazyPage(() =>
|
|
35
|
+
* import('./pages/Article.js').then((m) => ({ default: m.Article })),
|
|
36
|
+
* )
|
|
37
|
+
*
|
|
38
|
+
* const app = (
|
|
39
|
+
* <BrowserRouter>
|
|
40
|
+
* <Routes>
|
|
41
|
+
* <Route path="/" element={<Home />} />
|
|
42
|
+
* <Route path="/article/:slug" element={<Article />} />
|
|
43
|
+
* </Routes>
|
|
44
|
+
* </BrowserRouter>
|
|
45
|
+
* )
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function lazyPage(load, options = {}) {
|
|
49
|
+
const Loaded = lazy(load);
|
|
50
|
+
const fallback = options.fallback ?? null;
|
|
51
|
+
/**
|
|
52
|
+
* The page inside its own Suspense boundary.
|
|
53
|
+
*
|
|
54
|
+
* @param props - The page's props, passed through.
|
|
55
|
+
* @returns The page, or `fallback` while its code loads.
|
|
56
|
+
*/
|
|
57
|
+
function LazyPage(props) {
|
|
58
|
+
return (_jsx(Suspense, { fallback: fallback, children: _jsx(Loaded, { ...props }) }));
|
|
59
|
+
}
|
|
60
|
+
return LazyPage;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=lazyPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazyPage.js","sourceRoot":"","sources":["../src/lazyPage.tsx"],"names":[],"mappings":";AAAA;;;;GAIG;AAEH,OAAO,EAIL,IAAI,EAEJ,QAAQ,GACT,MAAM,OAAO,CAAA;AAWd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,QAAQ,CACtB,IAAsC,EACtC,UAA2B,EAAE;IAE7B,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAA;IACzB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAA;IACzC;;;;;OAKG;IACH,SAAS,QAAQ,CAAC,KAAwC;QACxD,OAAO,CACL,KAAC,QAAQ,IAAC,QAAQ,EAAE,QAAQ,YAC1B,KAAC,MAAM,OAAK,KAAK,GAAI,GACZ,CACZ,CAAA;IACH,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Router components with transitions turned off.
|
|
3
|
+
*
|
|
4
|
+
* Each wrapper renders React Router's own router with `useTransitions={false}`, so a
|
|
5
|
+
* navigation renders the new route in the same commit that changes the URL instead of
|
|
6
|
+
* keeping the previous route on screen while the next one prepares. That alone does not
|
|
7
|
+
* cover a page whose code loads on demand: under one shared `<Suspense>` React keeps
|
|
8
|
+
* the previous page mounted (hidden) until the new page's code arrives. Declare such
|
|
9
|
+
* pages with {@link lazyPage}, which gives each page a boundary of its own. React Router
|
|
10
|
+
* versions without the `useTransitions` prop ignore it.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import type { JSX } from 'react';
|
|
15
|
+
import { type BrowserRouterProps as ReactRouterBrowserRouterProps, type HashRouterProps as ReactRouterHashRouterProps, type HistoryRouterProps as ReactRouterHistoryRouterProps, type MemoryRouterProps as ReactRouterMemoryRouterProps, type RouterProps as ReactRouterProps, type RouterProviderProps as ReactRouterProviderProps } from 'react-router';
|
|
16
|
+
import type { Router as MoleculeRouter } from '@molecule/app-routing';
|
|
17
|
+
/** The molecule router interface, retained alongside the React Router component value. */
|
|
18
|
+
export type Router = MoleculeRouter;
|
|
19
|
+
/** Props for {@link BrowserRouter}, with transitions permanently disabled. */
|
|
20
|
+
export type BrowserRouterProps = Omit<ReactRouterBrowserRouterProps, 'useTransitions'>;
|
|
21
|
+
/** Props for {@link HashRouter}, with transitions permanently disabled. */
|
|
22
|
+
export type HashRouterProps = Omit<ReactRouterHashRouterProps, 'useTransitions'>;
|
|
23
|
+
/** Props for {@link MemoryRouter}, with transitions permanently disabled. */
|
|
24
|
+
export type MemoryRouterProps = Omit<ReactRouterMemoryRouterProps, 'useTransitions'>;
|
|
25
|
+
/** Props for {@link unstable_HistoryRouter}, with transitions permanently disabled. */
|
|
26
|
+
export type HistoryRouterProps = Omit<ReactRouterHistoryRouterProps, 'useTransitions'>;
|
|
27
|
+
/** Props for {@link Router}, with transitions permanently disabled. */
|
|
28
|
+
export type RouterProps = Omit<ReactRouterProps, 'useTransitions'>;
|
|
29
|
+
/** Props for {@link RouterProvider}, with transitions permanently disabled. */
|
|
30
|
+
export type RouterProviderProps = Omit<ReactRouterProviderProps, 'useTransitions'>;
|
|
31
|
+
/**
|
|
32
|
+
* Browser router that commits the URL and rendered page together.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* import { BrowserRouter } from '@molecule/app-routing-react-router'
|
|
37
|
+
*
|
|
38
|
+
* const app = <BrowserRouter><Routes /></BrowserRouter>
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function BrowserRouter(props: BrowserRouterProps): JSX.Element;
|
|
42
|
+
/**
|
|
43
|
+
* Hash router that commits the URL and rendered page together.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* import { HashRouter } from '@molecule/app-routing-react-router'
|
|
48
|
+
*
|
|
49
|
+
* const app = <HashRouter><Routes /></HashRouter>
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function HashRouter(props: HashRouterProps): JSX.Element;
|
|
53
|
+
/**
|
|
54
|
+
* In-memory router that commits its location and rendered page together.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```tsx
|
|
58
|
+
* import { MemoryRouter } from '@molecule/app-routing-react-router'
|
|
59
|
+
*
|
|
60
|
+
* const app = <MemoryRouter initialEntries={['/']}><Routes /></MemoryRouter>
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function MemoryRouter(props: MemoryRouterProps): JSX.Element;
|
|
64
|
+
/**
|
|
65
|
+
* Low-level router that commits its location and rendered page together.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```tsx
|
|
69
|
+
* import { Router } from '@molecule/app-routing-react-router'
|
|
70
|
+
*
|
|
71
|
+
* const app = <Router location={location} navigator={navigator}><Routes /></Router>
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function Router(props: RouterProps): JSX.Element;
|
|
75
|
+
/**
|
|
76
|
+
* Data-router provider that commits the URL and rendered page together.
|
|
77
|
+
*
|
|
78
|
+
* This is React Router's renderer-neutral provider. In a DOM app, import
|
|
79
|
+
* `RouterProvider` from `@molecule/app-routing-react-router/dom` instead, which
|
|
80
|
+
* supplies `react-dom`'s `flushSync` the way `react-router/dom` does.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* import { RouterProvider } from '@molecule/app-routing-react-router'
|
|
85
|
+
*
|
|
86
|
+
* const app = <RouterProvider router={router} flushSync={flushSync} />
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function RouterProvider(props: RouterProviderProps): JSX.Element;
|
|
90
|
+
/**
|
|
91
|
+
* History router that commits the URL and rendered page together.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```tsx
|
|
95
|
+
* import { unstable_HistoryRouter } from '@molecule/app-routing-react-router'
|
|
96
|
+
*
|
|
97
|
+
* const app = <unstable_HistoryRouter history={history}><Routes /></unstable_HistoryRouter>
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
declare function HistoryRouter(props: HistoryRouterProps): JSX.Element;
|
|
101
|
+
export { HistoryRouter as unstable_HistoryRouter };
|
|
102
|
+
//# sourceMappingURL=routers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routers.d.ts","sourceRoot":"","sources":["../src/routers.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EAEL,KAAK,kBAAkB,IAAI,6BAA6B,EAExD,KAAK,eAAe,IAAI,0BAA0B,EAClD,KAAK,kBAAkB,IAAI,6BAA6B,EAExD,KAAK,iBAAiB,IAAI,4BAA4B,EAEtD,KAAK,WAAW,IAAI,gBAAgB,EAEpC,KAAK,mBAAmB,IAAI,wBAAwB,EAErD,MAAM,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAErE,0FAA0F;AAC1F,MAAM,MAAM,MAAM,GAAG,cAAc,CAAA;AAEnC,8EAA8E;AAC9E,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,6BAA6B,EAAE,gBAAgB,CAAC,CAAA;AAEtF,2EAA2E;AAC3E,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,0BAA0B,EAAE,gBAAgB,CAAC,CAAA;AAEhF,6EAA6E;AAC7E,MAAM,MAAM,iB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