reactive-route 0.0.1-alpha.30 → 0.0.1-alpha.32
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/index.d.ts +1 -1
- package/core/index.d.ts.map +1 -1
- package/core/types/TypeRouter.d.ts +1 -0
- package/core/types/TypeRouter.d.ts.map +1 -1
- package/core/utils/routerSetLoadedComponent.d.ts +7 -0
- package/core/utils/routerSetLoadedComponent.d.ts.map +1 -0
- package/index.cjs +50 -19
- package/index.mjs +50 -19
- package/package.json +15 -18
- package/preact/Router.d.ts.map +1 -1
- package/preact/index.cjs +4 -41
- package/preact/index.mjs +6 -43
- package/react/Router.d.ts.map +1 -1
- package/react/index.cjs +4 -41
- package/react/index.mjs +6 -43
- package/solid/Router.d.ts.map +1 -1
- package/solid/index.cjs +3 -51
- package/solid/index.mjs +4 -52
- package/vue/index.cjs +0 -0
- package/vue/index.mjs +0 -0
- package/core/utils/history.d.ts +0 -7
- package/core/utils/history.d.ts.map +0 -1
|
@@ -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;
|
|
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,CAqQtB"}
|
package/core/index.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ export type { TypePropsRouter } from './types/TypePropsRouter';
|
|
|
6
6
|
export type { TypeRedirectParams } from './types/TypeRedirectParams';
|
|
7
7
|
export type { TypeRoute } from './types/TypeRoute';
|
|
8
8
|
export type { TypeRouter } from './types/TypeRouter';
|
|
9
|
-
export { history } from './utils/history';
|
|
10
9
|
export { loadComponentToConfig } from './utils/loadComponentToConfig';
|
|
11
10
|
export { RedirectError } from './utils/RedirectError';
|
|
12
11
|
export { replaceDynamicValues } from './utils/replaceDynamicValues';
|
|
12
|
+
export { routerSetLoadedComponent } from './utils/routerSetLoadedComponent';
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
package/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,YAAY,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,YAAY,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -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,CAAC,MAAM,GAAG,UAAU,GAAG,eAAe,EAAE,SAAS,CAAC,IAAI;IACjG,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,YAAY,CAAC;IACvB,YAAY,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC;IACvD,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC7B,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,UAAU,SAAS,MAAM,OAAO,EACvC,MAAM,EAAE,kBAAkB,CAAC,OAAO,EAAE,UAAU,CAAC,GAC9C,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,cAAc,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/E,iBAAiB,CAAC,GAAG,EAAE;QACrB,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAC7B,YAAY,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC;KACxD,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClB,eAAe,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;
|
|
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,CAAC,MAAM,GAAG,UAAU,GAAG,eAAe,EAAE,SAAS,CAAC,IAAI;IACjG,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,YAAY,CAAC;IACvB,YAAY,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC;IACvD,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC7B,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,UAAU,SAAS,MAAM,OAAO,EACvC,MAAM,EAAE,kBAAkB,CAAC,OAAO,EAAE,UAAU,CAAC,GAC9C,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,cAAc,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/E,iBAAiB,CAAC,GAAG,EAAE;QACrB,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAC7B,YAAY,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC;KACxD,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClB,eAAe,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TypePropsRouter } from '../types/TypePropsRouter';
|
|
2
|
+
export declare function routerSetLoadedComponent(props: TypePropsRouter<any>, config: {
|
|
3
|
+
loadedComponentName?: any;
|
|
4
|
+
loadedComponentPage?: string;
|
|
5
|
+
currentProps: Record<string, any>;
|
|
6
|
+
}): void;
|
|
7
|
+
//# sourceMappingURL=routerSetLoadedComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routerSetLoadedComponent.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/routerSetLoadedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,eAAe,CAAC,GAAG,CAAC,EAC3B,MAAM,EAAE;IACN,mBAAmB,CAAC,EAAE,GAAG,CAAC;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACnC,QA8BF"}
|
package/index.cjs
CHANGED
|
@@ -23,9 +23,9 @@ __export(core_exports, {
|
|
|
23
23
|
RedirectError: () => RedirectError,
|
|
24
24
|
createRouter: () => createRouter,
|
|
25
25
|
createRoutes: () => createRoutes,
|
|
26
|
-
history: () => history,
|
|
27
26
|
loadComponentToConfig: () => loadComponentToConfig,
|
|
28
|
-
replaceDynamicValues: () => replaceDynamicValues
|
|
27
|
+
replaceDynamicValues: () => replaceDynamicValues,
|
|
28
|
+
routerSetLoadedComponent: () => routerSetLoadedComponent
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(core_exports);
|
|
31
31
|
|
|
@@ -135,10 +135,6 @@ function getInitialRoute(params) {
|
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
// packages/core/utils/history.ts
|
|
139
|
-
var import_history = require("history");
|
|
140
|
-
var history = constants.isClient ? (0, import_history.createBrowserHistory)() : null;
|
|
141
|
-
|
|
142
138
|
// packages/core/utils/loadComponentToConfig.ts
|
|
143
139
|
function loadComponentToConfig(params) {
|
|
144
140
|
const { route } = params;
|
|
@@ -195,6 +191,7 @@ function createRouter(config) {
|
|
|
195
191
|
redirect: void 0,
|
|
196
192
|
restoreFromURL: void 0,
|
|
197
193
|
restoreFromServer: void 0,
|
|
194
|
+
destroy: void 0,
|
|
198
195
|
get adapters() {
|
|
199
196
|
return config.adapters;
|
|
200
197
|
},
|
|
@@ -264,12 +261,8 @@ function createRouter(config) {
|
|
|
264
261
|
});
|
|
265
262
|
router.routesHistory.push(nextUrl);
|
|
266
263
|
});
|
|
267
|
-
if (
|
|
268
|
-
history
|
|
269
|
-
hash: history.location.hash,
|
|
270
|
-
search: nextSearch,
|
|
271
|
-
pathname: nextPathname
|
|
272
|
-
});
|
|
264
|
+
if (constants.isClient) {
|
|
265
|
+
window.history[replace ? "replaceState" : "pushState"](null, "", nextUrl);
|
|
273
266
|
}
|
|
274
267
|
}
|
|
275
268
|
return Promise.resolve();
|
|
@@ -350,18 +343,30 @@ function createRouter(config) {
|
|
|
350
343
|
const lastUrl = router.routesHistory[router.routesHistory.length - 1];
|
|
351
344
|
if (lastUrl !== nextUrl) {
|
|
352
345
|
router.routesHistory.push(nextUrl);
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
hash: history.location.hash,
|
|
357
|
-
search: "query" in config2 ? `?${queryString.stringify(config2.query)}` : "",
|
|
358
|
-
pathname: nextPathname
|
|
359
|
-
});
|
|
346
|
+
if (constants.isClient) {
|
|
347
|
+
window.history[replace ? "replaceState" : "pushState"](null, "", nextUrl);
|
|
348
|
+
}
|
|
360
349
|
}
|
|
361
350
|
router.isRedirecting = false;
|
|
362
351
|
});
|
|
363
352
|
return Promise.resolve();
|
|
364
353
|
};
|
|
354
|
+
function popHandler() {
|
|
355
|
+
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
|
+
void router.restoreFromURL({ pathname: currentUrl, replace: true });
|
|
361
|
+
}
|
|
362
|
+
if (constants.isClient) {
|
|
363
|
+
window.addEventListener("popstate", popHandler);
|
|
364
|
+
}
|
|
365
|
+
router.destroy = function destroy() {
|
|
366
|
+
if (constants.isClient) {
|
|
367
|
+
window.removeEventListener("popstate", popHandler);
|
|
368
|
+
}
|
|
369
|
+
};
|
|
365
370
|
return router;
|
|
366
371
|
}
|
|
367
372
|
|
|
@@ -377,3 +382,29 @@ function addNames(obj) {
|
|
|
377
382
|
function createRoutes(config) {
|
|
378
383
|
return addNames(config);
|
|
379
384
|
}
|
|
385
|
+
|
|
386
|
+
// packages/core/utils/routerSetLoadedComponent.ts
|
|
387
|
+
function routerSetLoadedComponent(props, config) {
|
|
388
|
+
const currentRouteName = props.router.currentRoute.name;
|
|
389
|
+
const currentRoutePage = props.router.currentRoute.pageId;
|
|
390
|
+
const componentConfig = props.router.routes[currentRouteName];
|
|
391
|
+
let preventRedirect = false;
|
|
392
|
+
if (props.router.isRedirecting) preventRedirect = true;
|
|
393
|
+
else if (config.loadedComponentName === currentRouteName) preventRedirect = true;
|
|
394
|
+
else if (config.loadedComponentPage != null && currentRouteName != null) {
|
|
395
|
+
if (config.loadedComponentPage === currentRoutePage) {
|
|
396
|
+
props.router.adapters.batch(() => {
|
|
397
|
+
config.currentProps = "props" in componentConfig ? componentConfig.props || {} : {};
|
|
398
|
+
});
|
|
399
|
+
preventRedirect = true;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (preventRedirect) return;
|
|
403
|
+
props.router.adapters.batch(() => {
|
|
404
|
+
if (config.loadedComponentName) props.beforeUpdatePageComponent?.();
|
|
405
|
+
props.beforeSetPageComponent?.(componentConfig);
|
|
406
|
+
config.currentProps = "props" in componentConfig ? componentConfig.props : {};
|
|
407
|
+
config.loadedComponentName = currentRouteName;
|
|
408
|
+
config.loadedComponentPage = componentConfig.pageId;
|
|
409
|
+
});
|
|
410
|
+
}
|
package/index.mjs
CHANGED
|
@@ -104,10 +104,6 @@ function getInitialRoute(params) {
|
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
// packages/core/utils/history.ts
|
|
108
|
-
import { createBrowserHistory } from "history";
|
|
109
|
-
var history = constants.isClient ? createBrowserHistory() : null;
|
|
110
|
-
|
|
111
107
|
// packages/core/utils/loadComponentToConfig.ts
|
|
112
108
|
function loadComponentToConfig(params) {
|
|
113
109
|
const { route } = params;
|
|
@@ -164,6 +160,7 @@ function createRouter(config) {
|
|
|
164
160
|
redirect: void 0,
|
|
165
161
|
restoreFromURL: void 0,
|
|
166
162
|
restoreFromServer: void 0,
|
|
163
|
+
destroy: void 0,
|
|
167
164
|
get adapters() {
|
|
168
165
|
return config.adapters;
|
|
169
166
|
},
|
|
@@ -233,12 +230,8 @@ function createRouter(config) {
|
|
|
233
230
|
});
|
|
234
231
|
router.routesHistory.push(nextUrl);
|
|
235
232
|
});
|
|
236
|
-
if (
|
|
237
|
-
history
|
|
238
|
-
hash: history.location.hash,
|
|
239
|
-
search: nextSearch,
|
|
240
|
-
pathname: nextPathname
|
|
241
|
-
});
|
|
233
|
+
if (constants.isClient) {
|
|
234
|
+
window.history[replace ? "replaceState" : "pushState"](null, "", nextUrl);
|
|
242
235
|
}
|
|
243
236
|
}
|
|
244
237
|
return Promise.resolve();
|
|
@@ -319,18 +312,30 @@ function createRouter(config) {
|
|
|
319
312
|
const lastUrl = router.routesHistory[router.routesHistory.length - 1];
|
|
320
313
|
if (lastUrl !== nextUrl) {
|
|
321
314
|
router.routesHistory.push(nextUrl);
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
hash: history.location.hash,
|
|
326
|
-
search: "query" in config2 ? `?${queryString.stringify(config2.query)}` : "",
|
|
327
|
-
pathname: nextPathname
|
|
328
|
-
});
|
|
315
|
+
if (constants.isClient) {
|
|
316
|
+
window.history[replace ? "replaceState" : "pushState"](null, "", nextUrl);
|
|
317
|
+
}
|
|
329
318
|
}
|
|
330
319
|
router.isRedirecting = false;
|
|
331
320
|
});
|
|
332
321
|
return Promise.resolve();
|
|
333
322
|
};
|
|
323
|
+
function popHandler() {
|
|
324
|
+
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
|
+
void router.restoreFromURL({ pathname: currentUrl, replace: true });
|
|
330
|
+
}
|
|
331
|
+
if (constants.isClient) {
|
|
332
|
+
window.addEventListener("popstate", popHandler);
|
|
333
|
+
}
|
|
334
|
+
router.destroy = function destroy() {
|
|
335
|
+
if (constants.isClient) {
|
|
336
|
+
window.removeEventListener("popstate", popHandler);
|
|
337
|
+
}
|
|
338
|
+
};
|
|
334
339
|
return router;
|
|
335
340
|
}
|
|
336
341
|
|
|
@@ -346,11 +351,37 @@ function addNames(obj) {
|
|
|
346
351
|
function createRoutes(config) {
|
|
347
352
|
return addNames(config);
|
|
348
353
|
}
|
|
354
|
+
|
|
355
|
+
// packages/core/utils/routerSetLoadedComponent.ts
|
|
356
|
+
function routerSetLoadedComponent(props, config) {
|
|
357
|
+
const currentRouteName = props.router.currentRoute.name;
|
|
358
|
+
const currentRoutePage = props.router.currentRoute.pageId;
|
|
359
|
+
const componentConfig = props.router.routes[currentRouteName];
|
|
360
|
+
let preventRedirect = false;
|
|
361
|
+
if (props.router.isRedirecting) preventRedirect = true;
|
|
362
|
+
else if (config.loadedComponentName === currentRouteName) preventRedirect = true;
|
|
363
|
+
else if (config.loadedComponentPage != null && currentRouteName != null) {
|
|
364
|
+
if (config.loadedComponentPage === currentRoutePage) {
|
|
365
|
+
props.router.adapters.batch(() => {
|
|
366
|
+
config.currentProps = "props" in componentConfig ? componentConfig.props || {} : {};
|
|
367
|
+
});
|
|
368
|
+
preventRedirect = true;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (preventRedirect) return;
|
|
372
|
+
props.router.adapters.batch(() => {
|
|
373
|
+
if (config.loadedComponentName) props.beforeUpdatePageComponent?.();
|
|
374
|
+
props.beforeSetPageComponent?.(componentConfig);
|
|
375
|
+
config.currentProps = "props" in componentConfig ? componentConfig.props : {};
|
|
376
|
+
config.loadedComponentName = currentRouteName;
|
|
377
|
+
config.loadedComponentPage = componentConfig.pageId;
|
|
378
|
+
});
|
|
379
|
+
}
|
|
349
380
|
export {
|
|
350
381
|
RedirectError,
|
|
351
382
|
createRouter,
|
|
352
383
|
createRoutes,
|
|
353
|
-
history,
|
|
354
384
|
loadComponentToConfig,
|
|
355
|
-
replaceDynamicValues
|
|
385
|
+
replaceDynamicValues,
|
|
386
|
+
routerSetLoadedComponent
|
|
356
387
|
};
|
package/package.json
CHANGED
|
@@ -2,15 +2,12 @@
|
|
|
2
2
|
"name": "reactive-route",
|
|
3
3
|
"author": "Dmitry Kazakov",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.0.1-alpha.
|
|
5
|
+
"version": "0.0.1-alpha.32",
|
|
6
6
|
"description": "Reactive Router for different frameworks",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/dkazakov8/reactive-route.git"
|
|
10
10
|
},
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"history": "5.3.0"
|
|
13
|
-
},
|
|
14
11
|
"engines": {
|
|
15
12
|
"node": ">=22"
|
|
16
13
|
},
|
|
@@ -20,6 +17,11 @@
|
|
|
20
17
|
"require": "./index.cjs",
|
|
21
18
|
"import": "./index.mjs"
|
|
22
19
|
},
|
|
20
|
+
"./solid": {
|
|
21
|
+
"types": "./solid/index.d.ts",
|
|
22
|
+
"require": "./solid/index.cjs",
|
|
23
|
+
"import": "./solid/index.mjs"
|
|
24
|
+
},
|
|
23
25
|
"./react": {
|
|
24
26
|
"types": "./react/index.d.ts",
|
|
25
27
|
"require": "./react/index.cjs",
|
|
@@ -30,21 +32,11 @@
|
|
|
30
32
|
"require": "./preact/index.cjs",
|
|
31
33
|
"import": "./preact/index.mjs"
|
|
32
34
|
},
|
|
33
|
-
"./solid": {
|
|
34
|
-
"types": "./solid/index.d.ts",
|
|
35
|
-
"require": "./solid/index.cjs",
|
|
36
|
-
"import": "./solid/index.mjs"
|
|
37
|
-
},
|
|
38
35
|
"./vue": {
|
|
39
36
|
"types": "./vue/index.d.ts",
|
|
40
37
|
"require": "./vue/index.cjs",
|
|
41
38
|
"import": "./vue/index.mjs"
|
|
42
39
|
},
|
|
43
|
-
"./adapters/vue": {
|
|
44
|
-
"types": "./adapters/vue.d.ts",
|
|
45
|
-
"require": "./adapters/vue.cjs",
|
|
46
|
-
"import": "./adapters/vue.mjs"
|
|
47
|
-
},
|
|
48
40
|
"./adapters/mobx-react": {
|
|
49
41
|
"types": "./adapters/mobx-react.d.ts",
|
|
50
42
|
"require": "./adapters/mobx-react.cjs",
|
|
@@ -70,15 +62,20 @@
|
|
|
70
62
|
"require": "./adapters/kr-observable-react.cjs",
|
|
71
63
|
"import": "./adapters/kr-observable-react.mjs"
|
|
72
64
|
},
|
|
65
|
+
"./adapters/kr-observable-preact": {
|
|
66
|
+
"types": "./adapters/kr-observable-preact.d.ts",
|
|
67
|
+
"require": "./adapters/kr-observable-preact.cjs",
|
|
68
|
+
"import": "./adapters/kr-observable-preact.mjs"
|
|
69
|
+
},
|
|
73
70
|
"./adapters/kr-observable-solid": {
|
|
74
71
|
"types": "./adapters/kr-observable-solid.d.ts",
|
|
75
72
|
"require": "./adapters/kr-observable-solid.cjs",
|
|
76
73
|
"import": "./adapters/kr-observable-solid.mjs"
|
|
77
74
|
},
|
|
78
|
-
"./adapters/
|
|
79
|
-
"types": "./adapters/
|
|
80
|
-
"require": "./adapters/
|
|
81
|
-
"import": "./adapters/
|
|
75
|
+
"./adapters/vue": {
|
|
76
|
+
"types": "./adapters/vue.d.ts",
|
|
77
|
+
"require": "./adapters/vue.cjs",
|
|
78
|
+
"import": "./adapters/vue.mjs"
|
|
82
79
|
}
|
|
83
80
|
},
|
|
84
81
|
"main": "./index.cjs",
|
package/preact/Router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../packages/preact/Router.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../packages/preact/Router.tsx"],"names":[],"mappings":"AACA,OAAO,EAA4B,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA6CtF,wBAAgB,MAAM,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,GAK1D,GAAG,CACzC"}
|
package/preact/index.cjs
CHANGED
|
@@ -30,20 +30,6 @@ var import_reactive_route = require("reactive-route");
|
|
|
30
30
|
var import_jsx_runtime = require("preact/jsx-runtime");
|
|
31
31
|
function RouterInner(props) {
|
|
32
32
|
const disposerRef = (0, import_hooks.useRef)(null);
|
|
33
|
-
const redirectOnHistoryPop = (0, import_hooks.useCallback)(() => {
|
|
34
|
-
if (!import_reactive_route.history) return;
|
|
35
|
-
import_reactive_route.history.listen((params) => {
|
|
36
|
-
if (params.action !== "POP") return;
|
|
37
|
-
const previousRoutePathname = props.router.routesHistory[props.router.routesHistory.length - 2];
|
|
38
|
-
if (previousRoutePathname === params.location.pathname) {
|
|
39
|
-
props.router.adapters.batch(() => props.router.routesHistory.pop());
|
|
40
|
-
}
|
|
41
|
-
void props.router.restoreFromURL({
|
|
42
|
-
pathname: import_reactive_route.history.location.pathname,
|
|
43
|
-
replace: true
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}, []);
|
|
47
33
|
const [config] = (0, import_hooks.useState)(
|
|
48
34
|
() => props.router.adapters.makeObservable({
|
|
49
35
|
loadedComponentName: void 0,
|
|
@@ -51,36 +37,13 @@ function RouterInner(props) {
|
|
|
51
37
|
currentProps: {}
|
|
52
38
|
})
|
|
53
39
|
);
|
|
54
|
-
const setLoadedComponent = (0, import_hooks.useCallback)(() => {
|
|
55
|
-
const { loadedComponentName, loadedComponentPage } = config;
|
|
56
|
-
const { currentRoute, isRedirecting } = props.router;
|
|
57
|
-
const componentConfig = props.router.routes[currentRoute.name];
|
|
58
|
-
let preventRedirect = false;
|
|
59
|
-
if (isRedirecting) preventRedirect = true;
|
|
60
|
-
else if (loadedComponentName === currentRoute.name) preventRedirect = true;
|
|
61
|
-
else if (loadedComponentPage != null && currentRoute.name != null) {
|
|
62
|
-
if (loadedComponentPage === currentRoute.pageId) {
|
|
63
|
-
props.router.adapters.batch(() => {
|
|
64
|
-
config.currentProps = "props" in componentConfig ? componentConfig.props || {} : {};
|
|
65
|
-
});
|
|
66
|
-
preventRedirect = true;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (preventRedirect) return;
|
|
70
|
-
props.router.adapters.batch(() => {
|
|
71
|
-
if (loadedComponentName) props.beforeUpdatePageComponent?.();
|
|
72
|
-
props.beforeSetPageComponent?.(componentConfig);
|
|
73
|
-
config.currentProps = "props" in componentConfig ? componentConfig.props || {} : {};
|
|
74
|
-
config.loadedComponentName = currentRoute.name;
|
|
75
|
-
config.loadedComponentPage = componentConfig.pageId;
|
|
76
|
-
});
|
|
77
|
-
}, []);
|
|
78
40
|
(0, import_hooks.useState)(() => {
|
|
79
41
|
props.router.adapters.batch(() => {
|
|
80
42
|
props.beforeMount?.();
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
43
|
+
(0, import_reactive_route.routerSetLoadedComponent)(props, config);
|
|
44
|
+
disposerRef.current = props.router.adapters.autorun(
|
|
45
|
+
() => (0, import_reactive_route.routerSetLoadedComponent)(props, config)
|
|
46
|
+
);
|
|
84
47
|
});
|
|
85
48
|
});
|
|
86
49
|
(0, import_hooks.useEffect)(() => {
|
package/preact/index.mjs
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
// packages/preact/Router.tsx
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { useEffect, useRef, useState } from "preact/hooks";
|
|
3
|
+
import { routerSetLoadedComponent } from "reactive-route";
|
|
4
4
|
import { jsx } from "preact/jsx-runtime";
|
|
5
5
|
function RouterInner(props) {
|
|
6
6
|
const disposerRef = useRef(null);
|
|
7
|
-
const redirectOnHistoryPop = useCallback(() => {
|
|
8
|
-
if (!history) return;
|
|
9
|
-
history.listen((params) => {
|
|
10
|
-
if (params.action !== "POP") return;
|
|
11
|
-
const previousRoutePathname = props.router.routesHistory[props.router.routesHistory.length - 2];
|
|
12
|
-
if (previousRoutePathname === params.location.pathname) {
|
|
13
|
-
props.router.adapters.batch(() => props.router.routesHistory.pop());
|
|
14
|
-
}
|
|
15
|
-
void props.router.restoreFromURL({
|
|
16
|
-
pathname: history.location.pathname,
|
|
17
|
-
replace: true
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
}, []);
|
|
21
7
|
const [config] = useState(
|
|
22
8
|
() => props.router.adapters.makeObservable({
|
|
23
9
|
loadedComponentName: void 0,
|
|
@@ -25,36 +11,13 @@ function RouterInner(props) {
|
|
|
25
11
|
currentProps: {}
|
|
26
12
|
})
|
|
27
13
|
);
|
|
28
|
-
const setLoadedComponent = useCallback(() => {
|
|
29
|
-
const { loadedComponentName, loadedComponentPage } = config;
|
|
30
|
-
const { currentRoute, isRedirecting } = props.router;
|
|
31
|
-
const componentConfig = props.router.routes[currentRoute.name];
|
|
32
|
-
let preventRedirect = false;
|
|
33
|
-
if (isRedirecting) preventRedirect = true;
|
|
34
|
-
else if (loadedComponentName === currentRoute.name) preventRedirect = true;
|
|
35
|
-
else if (loadedComponentPage != null && currentRoute.name != null) {
|
|
36
|
-
if (loadedComponentPage === currentRoute.pageId) {
|
|
37
|
-
props.router.adapters.batch(() => {
|
|
38
|
-
config.currentProps = "props" in componentConfig ? componentConfig.props || {} : {};
|
|
39
|
-
});
|
|
40
|
-
preventRedirect = true;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (preventRedirect) return;
|
|
44
|
-
props.router.adapters.batch(() => {
|
|
45
|
-
if (loadedComponentName) props.beforeUpdatePageComponent?.();
|
|
46
|
-
props.beforeSetPageComponent?.(componentConfig);
|
|
47
|
-
config.currentProps = "props" in componentConfig ? componentConfig.props || {} : {};
|
|
48
|
-
config.loadedComponentName = currentRoute.name;
|
|
49
|
-
config.loadedComponentPage = componentConfig.pageId;
|
|
50
|
-
});
|
|
51
|
-
}, []);
|
|
52
14
|
useState(() => {
|
|
53
15
|
props.router.adapters.batch(() => {
|
|
54
16
|
props.beforeMount?.();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
17
|
+
routerSetLoadedComponent(props, config);
|
|
18
|
+
disposerRef.current = props.router.adapters.autorun(
|
|
19
|
+
() => routerSetLoadedComponent(props, config)
|
|
20
|
+
);
|
|
58
21
|
});
|
|
59
22
|
});
|
|
60
23
|
useEffect(() => {
|
package/react/Router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../packages/react/Router.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../packages/react/Router.tsx"],"names":[],"mappings":"AACA,OAAO,EAA4B,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA6CtF,iBAAS,aAAa,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,GAK1D,GAAG,CACzC;AAED,eAAO,MAAM,MAAM,EAA0B,OAAO,aAAa,CAAC"}
|
package/react/index.cjs
CHANGED
|
@@ -30,20 +30,6 @@ var import_reactive_route = require("reactive-route");
|
|
|
30
30
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
31
|
function RouterInner(props) {
|
|
32
32
|
const disposerRef = (0, import_react.useRef)(null);
|
|
33
|
-
const redirectOnHistoryPop = (0, import_react.useCallback)(() => {
|
|
34
|
-
if (!import_reactive_route.history) return;
|
|
35
|
-
import_reactive_route.history.listen((params) => {
|
|
36
|
-
if (params.action !== "POP") return;
|
|
37
|
-
const previousRoutePathname = props.router.routesHistory[props.router.routesHistory.length - 2];
|
|
38
|
-
if (previousRoutePathname === params.location.pathname) {
|
|
39
|
-
props.router.adapters.batch(() => props.router.routesHistory.pop());
|
|
40
|
-
}
|
|
41
|
-
void props.router.restoreFromURL({
|
|
42
|
-
pathname: import_reactive_route.history.location.pathname,
|
|
43
|
-
replace: true
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}, []);
|
|
47
33
|
const [config] = (0, import_react.useState)(
|
|
48
34
|
() => props.router.adapters.makeObservable({
|
|
49
35
|
loadedComponentName: void 0,
|
|
@@ -51,36 +37,13 @@ function RouterInner(props) {
|
|
|
51
37
|
currentProps: {}
|
|
52
38
|
})
|
|
53
39
|
);
|
|
54
|
-
const setLoadedComponent = (0, import_react.useCallback)(() => {
|
|
55
|
-
const { loadedComponentName, loadedComponentPage } = config;
|
|
56
|
-
const { currentRoute, isRedirecting } = props.router;
|
|
57
|
-
const componentConfig = props.router.routes[currentRoute.name];
|
|
58
|
-
let preventRedirect = false;
|
|
59
|
-
if (isRedirecting) preventRedirect = true;
|
|
60
|
-
else if (loadedComponentName === currentRoute.name) preventRedirect = true;
|
|
61
|
-
else if (loadedComponentPage != null && currentRoute.name != null) {
|
|
62
|
-
if (loadedComponentPage === currentRoute.pageId) {
|
|
63
|
-
props.router.adapters.batch(() => {
|
|
64
|
-
config.currentProps = "props" in componentConfig ? componentConfig.props || {} : {};
|
|
65
|
-
});
|
|
66
|
-
preventRedirect = true;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (preventRedirect) return;
|
|
70
|
-
props.router.adapters.batch(() => {
|
|
71
|
-
if (loadedComponentName) props.beforeUpdatePageComponent?.();
|
|
72
|
-
props.beforeSetPageComponent?.(componentConfig);
|
|
73
|
-
config.currentProps = "props" in componentConfig ? componentConfig.props || {} : {};
|
|
74
|
-
config.loadedComponentName = currentRoute.name;
|
|
75
|
-
config.loadedComponentPage = componentConfig.pageId;
|
|
76
|
-
});
|
|
77
|
-
}, []);
|
|
78
40
|
(0, import_react.useState)(() => {
|
|
79
41
|
props.router.adapters.batch(() => {
|
|
80
42
|
props.beforeMount?.();
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
43
|
+
(0, import_reactive_route.routerSetLoadedComponent)(props, config);
|
|
44
|
+
disposerRef.current = props.router.adapters.autorun(
|
|
45
|
+
() => (0, import_reactive_route.routerSetLoadedComponent)(props, config)
|
|
46
|
+
);
|
|
84
47
|
});
|
|
85
48
|
});
|
|
86
49
|
(0, import_react.useEffect)(() => {
|
package/react/index.mjs
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
// packages/react/Router.tsx
|
|
2
|
-
import { memo,
|
|
3
|
-
import {
|
|
2
|
+
import { memo, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { routerSetLoadedComponent } from "reactive-route";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
function RouterInner(props) {
|
|
6
6
|
const disposerRef = useRef(null);
|
|
7
|
-
const redirectOnHistoryPop = useCallback(() => {
|
|
8
|
-
if (!history) return;
|
|
9
|
-
history.listen((params) => {
|
|
10
|
-
if (params.action !== "POP") return;
|
|
11
|
-
const previousRoutePathname = props.router.routesHistory[props.router.routesHistory.length - 2];
|
|
12
|
-
if (previousRoutePathname === params.location.pathname) {
|
|
13
|
-
props.router.adapters.batch(() => props.router.routesHistory.pop());
|
|
14
|
-
}
|
|
15
|
-
void props.router.restoreFromURL({
|
|
16
|
-
pathname: history.location.pathname,
|
|
17
|
-
replace: true
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
}, []);
|
|
21
7
|
const [config] = useState(
|
|
22
8
|
() => props.router.adapters.makeObservable({
|
|
23
9
|
loadedComponentName: void 0,
|
|
@@ -25,36 +11,13 @@ function RouterInner(props) {
|
|
|
25
11
|
currentProps: {}
|
|
26
12
|
})
|
|
27
13
|
);
|
|
28
|
-
const setLoadedComponent = useCallback(() => {
|
|
29
|
-
const { loadedComponentName, loadedComponentPage } = config;
|
|
30
|
-
const { currentRoute, isRedirecting } = props.router;
|
|
31
|
-
const componentConfig = props.router.routes[currentRoute.name];
|
|
32
|
-
let preventRedirect = false;
|
|
33
|
-
if (isRedirecting) preventRedirect = true;
|
|
34
|
-
else if (loadedComponentName === currentRoute.name) preventRedirect = true;
|
|
35
|
-
else if (loadedComponentPage != null && currentRoute.name != null) {
|
|
36
|
-
if (loadedComponentPage === currentRoute.pageId) {
|
|
37
|
-
props.router.adapters.batch(() => {
|
|
38
|
-
config.currentProps = "props" in componentConfig ? componentConfig.props || {} : {};
|
|
39
|
-
});
|
|
40
|
-
preventRedirect = true;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (preventRedirect) return;
|
|
44
|
-
props.router.adapters.batch(() => {
|
|
45
|
-
if (loadedComponentName) props.beforeUpdatePageComponent?.();
|
|
46
|
-
props.beforeSetPageComponent?.(componentConfig);
|
|
47
|
-
config.currentProps = "props" in componentConfig ? componentConfig.props || {} : {};
|
|
48
|
-
config.loadedComponentName = currentRoute.name;
|
|
49
|
-
config.loadedComponentPage = componentConfig.pageId;
|
|
50
|
-
});
|
|
51
|
-
}, []);
|
|
52
14
|
useState(() => {
|
|
53
15
|
props.router.adapters.batch(() => {
|
|
54
16
|
props.beforeMount?.();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
17
|
+
routerSetLoadedComponent(props, config);
|
|
18
|
+
disposerRef.current = props.router.adapters.autorun(
|
|
19
|
+
() => routerSetLoadedComponent(props, config)
|
|
20
|
+
);
|
|
58
21
|
});
|
|
59
22
|
});
|
|
60
23
|
useEffect(() => {
|
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,
|
|
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,kCAkChG"}
|
package/solid/index.cjs
CHANGED
|
@@ -36,58 +36,13 @@ function Router(props) {
|
|
|
36
36
|
loadedComponentPage: void 0,
|
|
37
37
|
currentProps: {}
|
|
38
38
|
});
|
|
39
|
-
let currentProps = {};
|
|
40
|
-
function redirectOnHistoryPop() {
|
|
41
|
-
if (!import_reactive_route.history) return;
|
|
42
|
-
import_reactive_route.history.listen((params) => {
|
|
43
|
-
if (params.action !== "POP") return;
|
|
44
|
-
const previousRoutePathname = props.router.routesHistory[props.router.routesHistory.length - 2];
|
|
45
|
-
if (previousRoutePathname === params.location.pathname) {
|
|
46
|
-
props.router.routesHistory.pop();
|
|
47
|
-
}
|
|
48
|
-
void props.router.restoreFromURL({
|
|
49
|
-
pathname: import_reactive_route.history.location.pathname,
|
|
50
|
-
replace: true
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function setLoadedComponent() {
|
|
55
|
-
const currentRouteName = props.router.currentRoute.name;
|
|
56
|
-
const currentRoutePage = props.router.currentRoute.pageId;
|
|
57
|
-
const componentConfig = props.router.routes[currentRouteName];
|
|
58
|
-
let preventRedirect = false;
|
|
59
|
-
if (props.router.isRedirecting) preventRedirect = true;
|
|
60
|
-
else if (config.loadedComponentName === currentRouteName) {
|
|
61
|
-
preventRedirect = true;
|
|
62
|
-
} else if (config.loadedComponentPage != null && currentRouteName != null) {
|
|
63
|
-
if (config.loadedComponentPage === currentRoutePage) {
|
|
64
|
-
props.router.adapters.replaceObject(config.currentProps, "props" in componentConfig ? componentConfig.props : {});
|
|
65
|
-
currentProps = "props" in componentConfig ? componentConfig.props : {};
|
|
66
|
-
preventRedirect = true;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (preventRedirect) return;
|
|
70
|
-
props.router.adapters.batch(() => {
|
|
71
|
-
if (config.loadedComponentName) {
|
|
72
|
-
props.beforeUpdatePageComponent?.();
|
|
73
|
-
}
|
|
74
|
-
props.beforeSetPageComponent?.(componentConfig);
|
|
75
|
-
props.router.adapters.batch(() => {
|
|
76
|
-
props.router.adapters.replaceObject(config.currentProps, "props" in componentConfig ? componentConfig.props : {});
|
|
77
|
-
currentProps = "props" in componentConfig ? componentConfig.props : {};
|
|
78
|
-
config.loadedComponentName = currentRouteName;
|
|
79
|
-
config.loadedComponentPage = componentConfig.pageId;
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
39
|
props.beforeMount?.();
|
|
84
|
-
redirectOnHistoryPop();
|
|
85
40
|
if (props.router.adapters.immediateSetComponent) {
|
|
86
41
|
props.router.adapters.batch(() => {
|
|
87
|
-
|
|
42
|
+
(0, import_reactive_route.routerSetLoadedComponent)(props, config);
|
|
88
43
|
});
|
|
89
44
|
}
|
|
90
|
-
props.router.adapters.autorun(() =>
|
|
45
|
+
props.router.adapters.autorun(() => (0, import_reactive_route.routerSetLoadedComponent)(props, config));
|
|
91
46
|
return (
|
|
92
47
|
// @ts-ignore
|
|
93
48
|
(0, import_web.createComponent)(import_solid_js.Show, {
|
|
@@ -99,10 +54,7 @@ function Router(props) {
|
|
|
99
54
|
get component() {
|
|
100
55
|
return props.router.routes[config.loadedComponentName]?.component || void 0;
|
|
101
56
|
}
|
|
102
|
-
}, () =>
|
|
103
|
-
acc[key] = currentProps[key];
|
|
104
|
-
return acc;
|
|
105
|
-
}, {}), {
|
|
57
|
+
}, () => config.currentProps, {
|
|
106
58
|
get router() {
|
|
107
59
|
return props.router;
|
|
108
60
|
}
|
package/solid/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// packages/solid/Router.tsx
|
|
2
2
|
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
3
|
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
4
|
-
import {
|
|
4
|
+
import { routerSetLoadedComponent } from "reactive-route";
|
|
5
5
|
import { Show } from "solid-js";
|
|
6
6
|
import { Dynamic } from "solid-js/web";
|
|
7
7
|
function Router(props) {
|
|
@@ -10,58 +10,13 @@ function Router(props) {
|
|
|
10
10
|
loadedComponentPage: void 0,
|
|
11
11
|
currentProps: {}
|
|
12
12
|
});
|
|
13
|
-
let currentProps = {};
|
|
14
|
-
function redirectOnHistoryPop() {
|
|
15
|
-
if (!history) return;
|
|
16
|
-
history.listen((params) => {
|
|
17
|
-
if (params.action !== "POP") return;
|
|
18
|
-
const previousRoutePathname = props.router.routesHistory[props.router.routesHistory.length - 2];
|
|
19
|
-
if (previousRoutePathname === params.location.pathname) {
|
|
20
|
-
props.router.routesHistory.pop();
|
|
21
|
-
}
|
|
22
|
-
void props.router.restoreFromURL({
|
|
23
|
-
pathname: history.location.pathname,
|
|
24
|
-
replace: true
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
function setLoadedComponent() {
|
|
29
|
-
const currentRouteName = props.router.currentRoute.name;
|
|
30
|
-
const currentRoutePage = props.router.currentRoute.pageId;
|
|
31
|
-
const componentConfig = props.router.routes[currentRouteName];
|
|
32
|
-
let preventRedirect = false;
|
|
33
|
-
if (props.router.isRedirecting) preventRedirect = true;
|
|
34
|
-
else if (config.loadedComponentName === currentRouteName) {
|
|
35
|
-
preventRedirect = true;
|
|
36
|
-
} else if (config.loadedComponentPage != null && currentRouteName != null) {
|
|
37
|
-
if (config.loadedComponentPage === currentRoutePage) {
|
|
38
|
-
props.router.adapters.replaceObject(config.currentProps, "props" in componentConfig ? componentConfig.props : {});
|
|
39
|
-
currentProps = "props" in componentConfig ? componentConfig.props : {};
|
|
40
|
-
preventRedirect = true;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (preventRedirect) return;
|
|
44
|
-
props.router.adapters.batch(() => {
|
|
45
|
-
if (config.loadedComponentName) {
|
|
46
|
-
props.beforeUpdatePageComponent?.();
|
|
47
|
-
}
|
|
48
|
-
props.beforeSetPageComponent?.(componentConfig);
|
|
49
|
-
props.router.adapters.batch(() => {
|
|
50
|
-
props.router.adapters.replaceObject(config.currentProps, "props" in componentConfig ? componentConfig.props : {});
|
|
51
|
-
currentProps = "props" in componentConfig ? componentConfig.props : {};
|
|
52
|
-
config.loadedComponentName = currentRouteName;
|
|
53
|
-
config.loadedComponentPage = componentConfig.pageId;
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
13
|
props.beforeMount?.();
|
|
58
|
-
redirectOnHistoryPop();
|
|
59
14
|
if (props.router.adapters.immediateSetComponent) {
|
|
60
15
|
props.router.adapters.batch(() => {
|
|
61
|
-
|
|
16
|
+
routerSetLoadedComponent(props, config);
|
|
62
17
|
});
|
|
63
18
|
}
|
|
64
|
-
props.router.adapters.autorun(() =>
|
|
19
|
+
props.router.adapters.autorun(() => routerSetLoadedComponent(props, config));
|
|
65
20
|
return (
|
|
66
21
|
// @ts-ignore
|
|
67
22
|
_$createComponent(Show, {
|
|
@@ -73,10 +28,7 @@ function Router(props) {
|
|
|
73
28
|
get component() {
|
|
74
29
|
return props.router.routes[config.loadedComponentName]?.component || void 0;
|
|
75
30
|
}
|
|
76
|
-
}, () =>
|
|
77
|
-
acc[key] = currentProps[key];
|
|
78
|
-
return acc;
|
|
79
|
-
}, {}), {
|
|
31
|
+
}, () => config.currentProps, {
|
|
80
32
|
get router() {
|
|
81
33
|
return props.router;
|
|
82
34
|
}
|
package/vue/index.cjs
CHANGED
|
Binary file
|
package/vue/index.mjs
CHANGED
|
Binary file
|
package/core/utils/history.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAI/C;;;GAGG;AAEH,eAAO,MAAM,OAAO,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAEnD,CAAC"}
|