@tramvai/module-router 1.76.0 → 1.77.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.browser.js +29 -11
- package/package.json +14 -14
package/lib/index.browser.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { provide, commandLineListTokens, Module, DI_TOKEN, COMMAND_LINE_RUNNER_TOKEN } from '@tramvai/core';
|
|
2
2
|
import { Provider, setLogger, NoSpaRouter, Router } from '@tinkoff/router';
|
|
3
3
|
export { Link, Provider, useNavigate, useRoute, useRouter, useUrl } from '@tinkoff/router';
|
|
4
|
+
import noop from '@tinkoff/utils/function/noop';
|
|
4
5
|
import { LOGGER_TOKEN, BUNDLE_MANAGER_TOKEN, ACTION_REGISTRY_TOKEN, RESPONSE_MANAGER_TOKEN, CONTEXT_TOKEN, COMPONENT_REGISTRY_TOKEN, COMBINE_REDUCERS, STORE_TOKEN, ACTION_PAGE_RUNNER_TOKEN } from '@tramvai/tokens-common';
|
|
5
6
|
import { ROUTER_GUARD_TOKEN, ROUTE_TRANSFORM_TOKEN, ROUTER_TOKEN, ROUTES_TOKEN, ROUTE_RESOLVE_TOKEN, ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN, PAGE_SERVICE_TOKEN } from '@tramvai/tokens-router';
|
|
6
7
|
export * from '@tramvai/tokens-router';
|
|
@@ -15,7 +16,6 @@ import React from 'react';
|
|
|
15
16
|
import { isFileSystemPageComponent, fileSystemPagesEnabled, getStaticFileSystemPages, fileSystemPageToRoute } from '@tramvai/experiments';
|
|
16
17
|
import uniq from '@tinkoff/utils/array/uniq';
|
|
17
18
|
import { isRedirectFoundError, isNotFoundError } from '@tinkoff/errors';
|
|
18
|
-
import noop from '@tinkoff/utils/function/noop';
|
|
19
19
|
import { __decorate } from 'tslib';
|
|
20
20
|
|
|
21
21
|
const setCurrentNavigation = createEvent('SET_CURRENT_ROUTE');
|
|
@@ -451,14 +451,9 @@ const providers = [
|
|
|
451
451
|
provide({
|
|
452
452
|
provide: commandLineListTokens.customerStart,
|
|
453
453
|
multi: true,
|
|
454
|
-
useFactory: ({ router, store
|
|
454
|
+
useFactory: ({ router, store }) => {
|
|
455
455
|
return async function routerInit() {
|
|
456
456
|
const currentRoute = store.getState(RouterStore).currentRoute;
|
|
457
|
-
// in client-side rendering mode, run navigation before hydration,
|
|
458
|
-
// because currentRoute from initialState can be undefined or incorrect
|
|
459
|
-
if (renderMode === 'client') {
|
|
460
|
-
await router.navigate(window.location.href);
|
|
461
|
-
}
|
|
462
457
|
return router.rehydrate({
|
|
463
458
|
to: currentRoute,
|
|
464
459
|
});
|
|
@@ -467,7 +462,6 @@ const providers = [
|
|
|
467
462
|
deps: {
|
|
468
463
|
router: ROUTER_TOKEN,
|
|
469
464
|
store: STORE_TOKEN,
|
|
470
|
-
renderMode: TRAMVAI_RENDER_MODE,
|
|
471
465
|
},
|
|
472
466
|
}),
|
|
473
467
|
provide({
|
|
@@ -495,9 +489,11 @@ const providers = [
|
|
|
495
489
|
provide: commandLineListTokens.clear,
|
|
496
490
|
multi: true,
|
|
497
491
|
useFactory: (deps) => {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
492
|
+
const currentRoute = deps.store.getState(RouterStore).currentRoute;
|
|
493
|
+
// in client-side rendering mode, action will be executed on first navigation
|
|
494
|
+
if (deps.renderMode === 'client' &&
|
|
495
|
+
(!currentRoute || (currentRoute && currentRoute.actualPath !== window.location.pathname))) {
|
|
496
|
+
return noop;
|
|
501
497
|
}
|
|
502
498
|
return runActionsFactory(deps);
|
|
503
499
|
},
|
|
@@ -509,6 +505,28 @@ const providers = [
|
|
|
509
505
|
renderMode: TRAMVAI_RENDER_MODE,
|
|
510
506
|
},
|
|
511
507
|
}),
|
|
508
|
+
provide({
|
|
509
|
+
provide: commandLineListTokens.clear,
|
|
510
|
+
multi: true,
|
|
511
|
+
useFactory: (deps) => {
|
|
512
|
+
return async function csrFirstNavigation() {
|
|
513
|
+
const currentRoute = deps.store.getState(RouterStore).currentRoute;
|
|
514
|
+
// in client-side rendering mode, if current route inconsistent with current location,
|
|
515
|
+
// run navigation to current location.
|
|
516
|
+
if (deps.renderMode === 'client' &&
|
|
517
|
+
(!currentRoute || (currentRoute && currentRoute.actualPath !== window.location.pathname))) {
|
|
518
|
+
return deps.router.navigate(window.location.href);
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
},
|
|
522
|
+
deps: {
|
|
523
|
+
store: STORE_TOKEN,
|
|
524
|
+
router: ROUTER_TOKEN,
|
|
525
|
+
actionRegistry: ACTION_REGISTRY_TOKEN,
|
|
526
|
+
actionPageRunner: ACTION_PAGE_RUNNER_TOKEN,
|
|
527
|
+
renderMode: TRAMVAI_RENDER_MODE,
|
|
528
|
+
},
|
|
529
|
+
}),
|
|
512
530
|
];
|
|
513
531
|
|
|
514
532
|
const generateForRoot = (mainModule) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-router",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.77.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"browser": {
|
|
@@ -25,22 +25,22 @@
|
|
|
25
25
|
"@tinkoff/errors": "0.2.18",
|
|
26
26
|
"@tinkoff/router": "0.1.70",
|
|
27
27
|
"@tinkoff/url": "0.7.37",
|
|
28
|
-
"@tramvai/tokens-render": "1.
|
|
29
|
-
"@tramvai/tokens-router": "1.
|
|
30
|
-
"@tramvai/tokens-server": "1.
|
|
31
|
-
"@tramvai/experiments": "1.
|
|
28
|
+
"@tramvai/tokens-render": "1.77.0",
|
|
29
|
+
"@tramvai/tokens-router": "1.77.0",
|
|
30
|
+
"@tramvai/tokens-server": "1.77.0",
|
|
31
|
+
"@tramvai/experiments": "1.77.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@tinkoff/utils": "^2.1.2",
|
|
35
|
-
"@tramvai/cli": "1.
|
|
36
|
-
"@tramvai/core": "1.
|
|
37
|
-
"@tramvai/module-log": "1.
|
|
38
|
-
"@tramvai/module-server": "1.
|
|
39
|
-
"@tramvai/papi": "1.
|
|
40
|
-
"@tramvai/state": "1.
|
|
41
|
-
"@tramvai/test-helpers": "1.
|
|
42
|
-
"@tramvai/test-mocks": "1.
|
|
43
|
-
"@tramvai/tokens-common": "1.
|
|
35
|
+
"@tramvai/cli": "1.77.0",
|
|
36
|
+
"@tramvai/core": "1.77.0",
|
|
37
|
+
"@tramvai/module-log": "1.77.0",
|
|
38
|
+
"@tramvai/module-server": "1.77.0",
|
|
39
|
+
"@tramvai/papi": "1.77.0",
|
|
40
|
+
"@tramvai/state": "1.77.0",
|
|
41
|
+
"@tramvai/test-helpers": "1.77.0",
|
|
42
|
+
"@tramvai/test-mocks": "1.77.0",
|
|
43
|
+
"@tramvai/tokens-common": "1.77.0",
|
|
44
44
|
"@tinkoff/dippy": "0.7.38",
|
|
45
45
|
"react": "*",
|
|
46
46
|
"tslib": "^2.0.3"
|