reactive-route 0.0.1-alpha.32 → 0.0.1-alpha.34
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/core/createRouter.d.ts.map +1 -1
- package/core/types/TypeRouter.d.ts +2 -4
- package/core/types/TypeRouter.d.ts.map +1 -1
- package/core/utils/getInitialRoute.d.ts +1 -0
- package/core/utils/getInitialRoute.d.ts.map +1 -1
- package/index.cjs +9 -19
- package/index.mjs +9 -19
- package/package.json +1 -1
- package/solid/Router.d.ts.map +1 -1
- package/solid/index.cjs +4 -1
- package/solid/index.mjs +5 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRouter.d.ts","sourceRoot":"","sources":["../../packages/core/createRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAWhD,wBAAgB,YAAY,CAC1B,OAAO,SAAS,MAAM,CAAC,MAAM,GAAG,UAAU,GAAG,eAAe,EAAE,SAAS,CAAC,EACxE,MAAM,EAAE;IACR,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,YAAY,CAAC;IACvB,eAAe,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CAC9B,GAAG,UAAU,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"createRouter.d.ts","sourceRoot":"","sources":["../../packages/core/createRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAWhD,wBAAgB,YAAY,CAC1B,OAAO,SAAS,MAAM,CAAC,MAAM,GAAG,UAAU,GAAG,eAAe,EAAE,SAAS,CAAC,EACxE,MAAM,EAAE;IACR,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,YAAY,CAAC;IACvB,eAAe,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CAC9B,GAAG,UAAU,CAAC,OAAO,CAAC,CAuPtB"}
|
|
@@ -6,15 +6,13 @@ export type TypeRouter<TRoutes extends Record<string | 'notFound' | 'internalErr
|
|
|
6
6
|
routes: TRoutes;
|
|
7
7
|
adapters: TypeAdapters;
|
|
8
8
|
currentRoute: TypeCurrentRoute<TRoutes[keyof TRoutes]>;
|
|
9
|
-
routesHistory: Array<string>;
|
|
10
9
|
isRedirecting: boolean;
|
|
11
|
-
redirect<TRouteName extends keyof TRoutes>(config: TypeRedirectParams<TRoutes, TRouteName>): Promise<
|
|
10
|
+
redirect<TRouteName extends keyof TRoutes>(config: TypeRedirectParams<TRoutes, TRouteName>): Promise<string>;
|
|
12
11
|
restoreFromURL(params: {
|
|
13
12
|
pathname: string;
|
|
14
13
|
replace?: boolean;
|
|
15
|
-
}): Promise<
|
|
14
|
+
}): Promise<string>;
|
|
16
15
|
restoreFromServer(obj: {
|
|
17
|
-
routesHistory: Array<string>;
|
|
18
16
|
currentRoute: TypeCurrentRoute<TRoutes[keyof TRoutes]>;
|
|
19
17
|
}): Promise<void>;
|
|
20
18
|
lifecycleParams?: Array<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeRouter.d.ts","sourceRoot":"","sources":["../../../packages/core/types/TypeRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,UAAU,CAAC,OAAO,SAAS,MAAM,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,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC"}
|
|
@@ -3,5 +3,6 @@ import { TypeRoute } from '../types/TypeRoute';
|
|
|
3
3
|
export declare function getInitialRoute<TRoutes extends Record<string | 'notFound' | 'internalError', TypeRoute>>(params: {
|
|
4
4
|
routes: TRoutes;
|
|
5
5
|
pathname: string;
|
|
6
|
+
replace?: boolean;
|
|
6
7
|
}): TypeRedirectParams<TRoutes, keyof TRoutes>;
|
|
7
8
|
//# sourceMappingURL=getInitialRoute.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInitialRoute.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/getInitialRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAK/C,wBAAgB,eAAe,CAC7B,OAAO,SAAS,MAAM,CAAC,MAAM,GAAG,UAAU,GAAG,eAAe,EAAE,SAAS,CAAC,EACxE,MAAM,EAAE;
|
|
1
|
+
{"version":3,"file":"getInitialRoute.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/getInitialRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAK/C,wBAAgB,eAAe,CAC7B,OAAO,SAAS,MAAM,CAAC,MAAM,GAAG,UAAU,GAAG,eAAe,EAAE,SAAS,CAAC,EACxE,MAAM,EAAE;IACR,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,kBAAkB,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,CAW7C"}
|
package/index.cjs
CHANGED
|
@@ -131,7 +131,8 @@ function getInitialRoute(params) {
|
|
|
131
131
|
return {
|
|
132
132
|
route: route.name,
|
|
133
133
|
query: getQueryValues({ route, pathname: params.pathname }),
|
|
134
|
-
params: getDynamicValues({ route, pathname: params.pathname })
|
|
134
|
+
params: getDynamicValues({ route, pathname: params.pathname }),
|
|
135
|
+
replace: params.replace
|
|
135
136
|
};
|
|
136
137
|
}
|
|
137
138
|
|
|
@@ -185,7 +186,6 @@ function replaceDynamicValues({
|
|
|
185
186
|
// packages/core/createRouter.ts
|
|
186
187
|
function createRouter(config) {
|
|
187
188
|
const router = config.adapters.makeObservable({
|
|
188
|
-
routesHistory: [],
|
|
189
189
|
currentRoute: {},
|
|
190
190
|
isRedirecting: false,
|
|
191
191
|
redirect: void 0,
|
|
@@ -204,7 +204,6 @@ function createRouter(config) {
|
|
|
204
204
|
});
|
|
205
205
|
router.restoreFromServer = function restoreFromServer(obj) {
|
|
206
206
|
router.adapters.batch(() => {
|
|
207
|
-
router.routesHistory.push(...obj.routesHistory || []);
|
|
208
207
|
Object.assign(router.currentRoute, obj.currentRoute);
|
|
209
208
|
});
|
|
210
209
|
const preloadedRouteName = Object.keys(router.routes).find(
|
|
@@ -251,7 +250,7 @@ function createRouter(config) {
|
|
|
251
250
|
nextUrl = `${nextPathname}?${nextSearch}`;
|
|
252
251
|
}
|
|
253
252
|
}
|
|
254
|
-
if (currentUrl === nextUrl) return
|
|
253
|
+
if (currentUrl === nextUrl) return nextUrl;
|
|
255
254
|
if (currentPathname === nextPathname) {
|
|
256
255
|
if (currentSearch !== nextSearch) {
|
|
257
256
|
router.adapters.batch(() => {
|
|
@@ -259,13 +258,12 @@ function createRouter(config) {
|
|
|
259
258
|
...router.currentRoute,
|
|
260
259
|
query: nextQuery || {}
|
|
261
260
|
});
|
|
262
|
-
router.routesHistory.push(nextUrl);
|
|
263
261
|
});
|
|
264
262
|
if (constants.isClient) {
|
|
265
263
|
window.history[replace ? "replaceState" : "pushState"](null, "", nextUrl);
|
|
266
264
|
}
|
|
267
265
|
}
|
|
268
|
-
return
|
|
266
|
+
return nextUrl;
|
|
269
267
|
}
|
|
270
268
|
router.adapters.batch(() => {
|
|
271
269
|
router.isRedirecting = true;
|
|
@@ -311,7 +309,7 @@ function createRouter(config) {
|
|
|
311
309
|
await loadComponentToConfig({ route: router.routes[nextRoute.name] });
|
|
312
310
|
} catch (error) {
|
|
313
311
|
if (error instanceof PreventError) {
|
|
314
|
-
return
|
|
312
|
+
return currentUrl;
|
|
315
313
|
}
|
|
316
314
|
if (error instanceof RedirectError) {
|
|
317
315
|
throw error;
|
|
@@ -329,7 +327,7 @@ function createRouter(config) {
|
|
|
329
327
|
});
|
|
330
328
|
router.isRedirecting = false;
|
|
331
329
|
});
|
|
332
|
-
return
|
|
330
|
+
return nextUrl;
|
|
333
331
|
}
|
|
334
332
|
router.adapters.batch(() => {
|
|
335
333
|
router.adapters.replaceObject(router.currentRoute, {
|
|
@@ -340,23 +338,15 @@ function createRouter(config) {
|
|
|
340
338
|
params: getDynamicValues({ route: nextRoute, pathname: nextUrl }),
|
|
341
339
|
pageId: router.routes[nextRoute.name].pageId
|
|
342
340
|
});
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
router.routesHistory.push(nextUrl);
|
|
346
|
-
if (constants.isClient) {
|
|
347
|
-
window.history[replace ? "replaceState" : "pushState"](null, "", nextUrl);
|
|
348
|
-
}
|
|
341
|
+
if (constants.isClient) {
|
|
342
|
+
window.history[replace ? "replaceState" : "pushState"](null, "", nextUrl);
|
|
349
343
|
}
|
|
350
344
|
router.isRedirecting = false;
|
|
351
345
|
});
|
|
352
|
-
return
|
|
346
|
+
return nextUrl;
|
|
353
347
|
};
|
|
354
348
|
function popHandler() {
|
|
355
349
|
const currentUrl = `${location.pathname}${location.search}`;
|
|
356
|
-
const previousUrl = router.routesHistory[router.routesHistory.length - 2];
|
|
357
|
-
if (previousUrl === currentUrl) {
|
|
358
|
-
router.adapters.batch(() => router.routesHistory.pop());
|
|
359
|
-
}
|
|
360
350
|
void router.restoreFromURL({ pathname: currentUrl, replace: true });
|
|
361
351
|
}
|
|
362
352
|
if (constants.isClient) {
|
package/index.mjs
CHANGED
|
@@ -100,7 +100,8 @@ function getInitialRoute(params) {
|
|
|
100
100
|
return {
|
|
101
101
|
route: route.name,
|
|
102
102
|
query: getQueryValues({ route, pathname: params.pathname }),
|
|
103
|
-
params: getDynamicValues({ route, pathname: params.pathname })
|
|
103
|
+
params: getDynamicValues({ route, pathname: params.pathname }),
|
|
104
|
+
replace: params.replace
|
|
104
105
|
};
|
|
105
106
|
}
|
|
106
107
|
|
|
@@ -154,7 +155,6 @@ function replaceDynamicValues({
|
|
|
154
155
|
// packages/core/createRouter.ts
|
|
155
156
|
function createRouter(config) {
|
|
156
157
|
const router = config.adapters.makeObservable({
|
|
157
|
-
routesHistory: [],
|
|
158
158
|
currentRoute: {},
|
|
159
159
|
isRedirecting: false,
|
|
160
160
|
redirect: void 0,
|
|
@@ -173,7 +173,6 @@ function createRouter(config) {
|
|
|
173
173
|
});
|
|
174
174
|
router.restoreFromServer = function restoreFromServer(obj) {
|
|
175
175
|
router.adapters.batch(() => {
|
|
176
|
-
router.routesHistory.push(...obj.routesHistory || []);
|
|
177
176
|
Object.assign(router.currentRoute, obj.currentRoute);
|
|
178
177
|
});
|
|
179
178
|
const preloadedRouteName = Object.keys(router.routes).find(
|
|
@@ -220,7 +219,7 @@ function createRouter(config) {
|
|
|
220
219
|
nextUrl = `${nextPathname}?${nextSearch}`;
|
|
221
220
|
}
|
|
222
221
|
}
|
|
223
|
-
if (currentUrl === nextUrl) return
|
|
222
|
+
if (currentUrl === nextUrl) return nextUrl;
|
|
224
223
|
if (currentPathname === nextPathname) {
|
|
225
224
|
if (currentSearch !== nextSearch) {
|
|
226
225
|
router.adapters.batch(() => {
|
|
@@ -228,13 +227,12 @@ function createRouter(config) {
|
|
|
228
227
|
...router.currentRoute,
|
|
229
228
|
query: nextQuery || {}
|
|
230
229
|
});
|
|
231
|
-
router.routesHistory.push(nextUrl);
|
|
232
230
|
});
|
|
233
231
|
if (constants.isClient) {
|
|
234
232
|
window.history[replace ? "replaceState" : "pushState"](null, "", nextUrl);
|
|
235
233
|
}
|
|
236
234
|
}
|
|
237
|
-
return
|
|
235
|
+
return nextUrl;
|
|
238
236
|
}
|
|
239
237
|
router.adapters.batch(() => {
|
|
240
238
|
router.isRedirecting = true;
|
|
@@ -280,7 +278,7 @@ function createRouter(config) {
|
|
|
280
278
|
await loadComponentToConfig({ route: router.routes[nextRoute.name] });
|
|
281
279
|
} catch (error) {
|
|
282
280
|
if (error instanceof PreventError) {
|
|
283
|
-
return
|
|
281
|
+
return currentUrl;
|
|
284
282
|
}
|
|
285
283
|
if (error instanceof RedirectError) {
|
|
286
284
|
throw error;
|
|
@@ -298,7 +296,7 @@ function createRouter(config) {
|
|
|
298
296
|
});
|
|
299
297
|
router.isRedirecting = false;
|
|
300
298
|
});
|
|
301
|
-
return
|
|
299
|
+
return nextUrl;
|
|
302
300
|
}
|
|
303
301
|
router.adapters.batch(() => {
|
|
304
302
|
router.adapters.replaceObject(router.currentRoute, {
|
|
@@ -309,23 +307,15 @@ function createRouter(config) {
|
|
|
309
307
|
params: getDynamicValues({ route: nextRoute, pathname: nextUrl }),
|
|
310
308
|
pageId: router.routes[nextRoute.name].pageId
|
|
311
309
|
});
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
router.routesHistory.push(nextUrl);
|
|
315
|
-
if (constants.isClient) {
|
|
316
|
-
window.history[replace ? "replaceState" : "pushState"](null, "", nextUrl);
|
|
317
|
-
}
|
|
310
|
+
if (constants.isClient) {
|
|
311
|
+
window.history[replace ? "replaceState" : "pushState"](null, "", nextUrl);
|
|
318
312
|
}
|
|
319
313
|
router.isRedirecting = false;
|
|
320
314
|
});
|
|
321
|
-
return
|
|
315
|
+
return nextUrl;
|
|
322
316
|
};
|
|
323
317
|
function popHandler() {
|
|
324
318
|
const currentUrl = `${location.pathname}${location.search}`;
|
|
325
|
-
const previousUrl = router.routesHistory[router.routesHistory.length - 2];
|
|
326
|
-
if (previousUrl === currentUrl) {
|
|
327
|
-
router.adapters.batch(() => router.routesHistory.pop());
|
|
328
|
-
}
|
|
329
319
|
void router.restoreFromURL({ pathname: currentUrl, replace: true });
|
|
330
320
|
}
|
|
331
321
|
if (constants.isClient) {
|
package/package.json
CHANGED
package/solid/Router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../packages/solid/Router.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA4B,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAItF,wBAAgB,MAAM,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../packages/solid/Router.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA4B,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAItF,wBAAgB,MAAM,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,kCAsChG"}
|
package/solid/index.cjs
CHANGED
|
@@ -42,7 +42,10 @@ function Router(props) {
|
|
|
42
42
|
(0, import_reactive_route.routerSetLoadedComponent)(props, config);
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
-
props.router.adapters.autorun(() => (0, import_reactive_route.routerSetLoadedComponent)(props, config));
|
|
45
|
+
const disposer = props.router.adapters.autorun(() => (0, import_reactive_route.routerSetLoadedComponent)(props, config));
|
|
46
|
+
(0, import_solid_js.onCleanup)(() => {
|
|
47
|
+
if (typeof disposer === "function") disposer();
|
|
48
|
+
});
|
|
46
49
|
return (
|
|
47
50
|
// @ts-ignore
|
|
48
51
|
(0, import_web.createComponent)(import_solid_js.Show, {
|
package/solid/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
3
|
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
4
4
|
import { routerSetLoadedComponent } from "reactive-route";
|
|
5
|
-
import { Show } from "solid-js";
|
|
5
|
+
import { onCleanup, Show } from "solid-js";
|
|
6
6
|
import { Dynamic } from "solid-js/web";
|
|
7
7
|
function Router(props) {
|
|
8
8
|
const config = props.router.adapters.makeObservable({
|
|
@@ -16,7 +16,10 @@ function Router(props) {
|
|
|
16
16
|
routerSetLoadedComponent(props, config);
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
props.router.adapters.autorun(() => routerSetLoadedComponent(props, config));
|
|
19
|
+
const disposer = props.router.adapters.autorun(() => routerSetLoadedComponent(props, config));
|
|
20
|
+
onCleanup(() => {
|
|
21
|
+
if (typeof disposer === "function") disposer();
|
|
22
|
+
});
|
|
20
23
|
return (
|
|
21
24
|
// @ts-ignore
|
|
22
25
|
_$createComponent(Show, {
|