@tramvai/module-router 1.82.2 → 1.84.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/lib/index.browser.js +22 -12
- package/lib/index.es.js +16 -7
- package/lib/index.js +15 -6
- package/lib/modules/hooks/spa/runCommands.d.ts +5 -1
- package/package.json +16 -16
package/lib/index.browser.js
CHANGED
|
@@ -509,22 +509,20 @@ const providers = [
|
|
|
509
509
|
provide({
|
|
510
510
|
provide: commandLineListTokens.clear,
|
|
511
511
|
multi: true,
|
|
512
|
-
useFactory: (
|
|
512
|
+
useFactory: ({ store, router, renderMode }) => {
|
|
513
513
|
return async function csrFirstNavigation() {
|
|
514
|
-
const currentRoute =
|
|
514
|
+
const currentRoute = store.getState(RouterStore).currentRoute;
|
|
515
515
|
// in client-side rendering mode, if current route inconsistent with current location,
|
|
516
516
|
// run navigation to current location.
|
|
517
|
-
if (
|
|
517
|
+
if (renderMode === 'client' &&
|
|
518
518
|
(!currentRoute || (currentRoute && currentRoute.actualPath !== window.location.pathname))) {
|
|
519
|
-
return
|
|
519
|
+
return router.navigate(window.location.href);
|
|
520
520
|
}
|
|
521
521
|
};
|
|
522
522
|
},
|
|
523
523
|
deps: {
|
|
524
524
|
store: STORE_TOKEN,
|
|
525
525
|
router: ROUTER_TOKEN,
|
|
526
|
-
actionRegistry: ACTION_REGISTRY_TOKEN,
|
|
527
|
-
actionPageRunner: ACTION_PAGE_RUNNER_TOKEN,
|
|
528
526
|
renderMode: TRAMVAI_RENDER_MODE,
|
|
529
527
|
},
|
|
530
528
|
}),
|
|
@@ -563,17 +561,31 @@ const NoSpaRouterModule = /* @__PURE__ */ Module({
|
|
|
563
561
|
_a$1.forRoot = generateForRoot(_a$1),
|
|
564
562
|
_a$1));
|
|
565
563
|
|
|
566
|
-
const
|
|
564
|
+
const runCommandsSpa = ({ commandLineRunner, di, }) => {
|
|
567
565
|
return async () => {
|
|
568
566
|
await commandLineRunner.run('client', 'spa', [], di);
|
|
569
567
|
};
|
|
570
568
|
};
|
|
569
|
+
const runCommandsAfterSpa = ({ commandLineRunner, di, }) => {
|
|
570
|
+
return async () => {
|
|
571
|
+
await commandLineRunner.run('client', 'afterSpa', [], di);
|
|
572
|
+
};
|
|
573
|
+
};
|
|
571
574
|
|
|
572
575
|
const spaHooks = [
|
|
573
576
|
{
|
|
574
577
|
provide: beforeNavigateHooksToken,
|
|
575
578
|
multi: true,
|
|
576
|
-
useFactory:
|
|
579
|
+
useFactory: runCommandsSpa,
|
|
580
|
+
deps: {
|
|
581
|
+
di: DI_TOKEN,
|
|
582
|
+
commandLineRunner: COMMAND_LINE_RUNNER_TOKEN,
|
|
583
|
+
},
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
provide: afterNavigateHooksToken,
|
|
587
|
+
multi: true,
|
|
588
|
+
useFactory: runCommandsAfterSpa,
|
|
577
589
|
deps: {
|
|
578
590
|
di: DI_TOKEN,
|
|
579
591
|
commandLineRunner: COMMAND_LINE_RUNNER_TOKEN,
|
|
@@ -600,13 +612,11 @@ const spaHooks = [
|
|
|
600
612
|
},
|
|
601
613
|
},
|
|
602
614
|
{
|
|
603
|
-
provide: commandLineListTokens.
|
|
615
|
+
provide: commandLineListTokens.afterSpaTransition,
|
|
604
616
|
multi: true,
|
|
605
617
|
useFactory: ({ spaMode, ...deps }) => {
|
|
606
618
|
if (spaMode === 'after') {
|
|
607
|
-
return
|
|
608
|
-
deps.router.registerHook('afterNavigate', runActionsFactory(deps));
|
|
609
|
-
};
|
|
619
|
+
return runActionsFactory(deps);
|
|
610
620
|
}
|
|
611
621
|
return noop;
|
|
612
622
|
},
|
package/lib/index.es.js
CHANGED
|
@@ -15,7 +15,7 @@ import replace from '@tinkoff/utils/string/replace';
|
|
|
15
15
|
import React from 'react';
|
|
16
16
|
import { isFileSystemPageComponent, fileSystemPagesEnabled, getStaticFileSystemPages, fileSystemPageToRoute } from '@tramvai/experiments';
|
|
17
17
|
import uniq from '@tinkoff/utils/array/uniq';
|
|
18
|
-
import { isRedirectFoundError, isNotFoundError,
|
|
18
|
+
import { isRedirectFoundError, isNotFoundError, throwRedirectFoundError, HttpError, makeErrorSilent } from '@tinkoff/errors';
|
|
19
19
|
import { SERVER_MODULE_PAPI_PUBLIC_ROUTE } from '@tramvai/tokens-server';
|
|
20
20
|
import prop from '@tinkoff/utils/object/prop';
|
|
21
21
|
import { createPapiMethod } from '@tramvai/papi';
|
|
@@ -500,24 +500,33 @@ const serverHooks = [
|
|
|
500
500
|
];
|
|
501
501
|
|
|
502
502
|
const routerOptions = ({ requestManager, responseManager, }) => {
|
|
503
|
-
const
|
|
504
|
-
|
|
503
|
+
const getUrl = (navigation) => { var _a, _b; return (_b = (_a = navigation.url) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : requestManager.getUrl(); };
|
|
504
|
+
const throwError = ({ defaultStatus, url, silent, }) => {
|
|
505
|
+
const error = new HttpError({
|
|
506
|
+
url,
|
|
505
507
|
httpStatus: responseManager.getStatus() >= 300 ? responseManager.getStatus() : defaultStatus,
|
|
506
508
|
});
|
|
509
|
+
if (silent) {
|
|
510
|
+
makeErrorSilent(error);
|
|
511
|
+
}
|
|
512
|
+
throw error;
|
|
507
513
|
};
|
|
508
514
|
return {
|
|
509
|
-
onNotFound: async () => {
|
|
510
|
-
|
|
515
|
+
onNotFound: async (navigation) => {
|
|
516
|
+
// isSilent is used to prevent command line error logs,
|
|
517
|
+
// because 404 errors is expected behavior
|
|
518
|
+
throwError({ defaultStatus: 404, url: getUrl(navigation), silent: true });
|
|
511
519
|
},
|
|
512
520
|
onRedirect: async (navigation) => {
|
|
513
521
|
const { fromUrl, url, code } = navigation;
|
|
514
522
|
throwRedirectFoundError({
|
|
523
|
+
url: getUrl(navigation),
|
|
515
524
|
nextUrl: fromUrl.origin !== url.origin ? url.href : url.path,
|
|
516
525
|
httpStatus: code,
|
|
517
526
|
});
|
|
518
527
|
},
|
|
519
|
-
onBlock: async () => {
|
|
520
|
-
throwError(500);
|
|
528
|
+
onBlock: async (navigation) => {
|
|
529
|
+
throwError({ defaultStatus: 500, url: getUrl(navigation) });
|
|
521
530
|
},
|
|
522
531
|
defaultRedirectCode: requestManager.getMethod() === 'GET' ? 301 : 308,
|
|
523
532
|
};
|
package/lib/index.js
CHANGED
|
@@ -512,24 +512,33 @@ const serverHooks = [
|
|
|
512
512
|
];
|
|
513
513
|
|
|
514
514
|
const routerOptions = ({ requestManager, responseManager, }) => {
|
|
515
|
-
const
|
|
516
|
-
|
|
515
|
+
const getUrl = (navigation) => { var _a, _b; return (_b = (_a = navigation.url) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : requestManager.getUrl(); };
|
|
516
|
+
const throwError = ({ defaultStatus, url, silent, }) => {
|
|
517
|
+
const error = new errors.HttpError({
|
|
518
|
+
url,
|
|
517
519
|
httpStatus: responseManager.getStatus() >= 300 ? responseManager.getStatus() : defaultStatus,
|
|
518
520
|
});
|
|
521
|
+
if (silent) {
|
|
522
|
+
errors.makeErrorSilent(error);
|
|
523
|
+
}
|
|
524
|
+
throw error;
|
|
519
525
|
};
|
|
520
526
|
return {
|
|
521
|
-
onNotFound: async () => {
|
|
522
|
-
|
|
527
|
+
onNotFound: async (navigation) => {
|
|
528
|
+
// isSilent is used to prevent command line error logs,
|
|
529
|
+
// because 404 errors is expected behavior
|
|
530
|
+
throwError({ defaultStatus: 404, url: getUrl(navigation), silent: true });
|
|
523
531
|
},
|
|
524
532
|
onRedirect: async (navigation) => {
|
|
525
533
|
const { fromUrl, url, code } = navigation;
|
|
526
534
|
errors.throwRedirectFoundError({
|
|
535
|
+
url: getUrl(navigation),
|
|
527
536
|
nextUrl: fromUrl.origin !== url.origin ? url.href : url.path,
|
|
528
537
|
httpStatus: code,
|
|
529
538
|
});
|
|
530
539
|
},
|
|
531
|
-
onBlock: async () => {
|
|
532
|
-
throwError(500);
|
|
540
|
+
onBlock: async (navigation) => {
|
|
541
|
+
throwError({ defaultStatus: 500, url: getUrl(navigation) });
|
|
533
542
|
},
|
|
534
543
|
defaultRedirectCode: requestManager.getMethod() === 'GET' ? 301 : 308,
|
|
535
544
|
};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { DI_TOKEN, COMMAND_LINE_RUNNER_TOKEN } from '@tramvai/core';
|
|
2
2
|
import type { NavigationHook } from '@tinkoff/router';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const runCommandsSpa: ({ commandLineRunner, di, }: {
|
|
4
|
+
di: typeof DI_TOKEN;
|
|
5
|
+
commandLineRunner: typeof COMMAND_LINE_RUNNER_TOKEN;
|
|
6
|
+
}) => NavigationHook;
|
|
7
|
+
export declare const runCommandsAfterSpa: ({ commandLineRunner, di, }: {
|
|
4
8
|
di: typeof DI_TOKEN;
|
|
5
9
|
commandLineRunner: typeof COMMAND_LINE_RUNNER_TOKEN;
|
|
6
10
|
}) => NavigationHook;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-router",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.84.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"browser": {
|
|
@@ -22,26 +22,26 @@
|
|
|
22
22
|
"build-for-publish": "true"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@tinkoff/errors": "0.2.
|
|
25
|
+
"@tinkoff/errors": "0.2.20",
|
|
26
26
|
"@tinkoff/router": "0.1.71",
|
|
27
27
|
"@tinkoff/url": "0.7.37",
|
|
28
|
-
"@tramvai/tokens-child-app": "1.
|
|
29
|
-
"@tramvai/tokens-render": "1.
|
|
30
|
-
"@tramvai/tokens-router": "1.
|
|
31
|
-
"@tramvai/tokens-server": "1.
|
|
32
|
-
"@tramvai/experiments": "1.
|
|
28
|
+
"@tramvai/tokens-child-app": "1.84.2",
|
|
29
|
+
"@tramvai/tokens-render": "1.84.2",
|
|
30
|
+
"@tramvai/tokens-router": "1.84.2",
|
|
31
|
+
"@tramvai/tokens-server": "1.84.2",
|
|
32
|
+
"@tramvai/experiments": "1.84.2"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@tinkoff/utils": "^2.1.2",
|
|
36
|
-
"@tramvai/cli": "1.
|
|
37
|
-
"@tramvai/core": "1.
|
|
38
|
-
"@tramvai/module-log": "1.
|
|
39
|
-
"@tramvai/module-server": "1.
|
|
40
|
-
"@tramvai/papi": "1.
|
|
41
|
-
"@tramvai/state": "1.
|
|
42
|
-
"@tramvai/test-helpers": "1.
|
|
43
|
-
"@tramvai/test-mocks": "1.
|
|
44
|
-
"@tramvai/tokens-common": "1.
|
|
36
|
+
"@tramvai/cli": "1.84.2",
|
|
37
|
+
"@tramvai/core": "1.84.2",
|
|
38
|
+
"@tramvai/module-log": "1.84.2",
|
|
39
|
+
"@tramvai/module-server": "1.84.2",
|
|
40
|
+
"@tramvai/papi": "1.84.2",
|
|
41
|
+
"@tramvai/state": "1.84.2",
|
|
42
|
+
"@tramvai/test-helpers": "1.84.2",
|
|
43
|
+
"@tramvai/test-mocks": "1.84.2",
|
|
44
|
+
"@tramvai/tokens-common": "1.84.2",
|
|
45
45
|
"@tinkoff/dippy": "0.7.39",
|
|
46
46
|
"react": "*",
|
|
47
47
|
"tslib": "^2.0.3"
|