@tinkoff/router 0.2.13 → 0.2.14
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/router/client.browser.js +19 -1
- package/lib/router/client.es.js +19 -1
- package/lib/router/client.js +19 -1
- package/package.json +1 -1
|
@@ -14,7 +14,25 @@ class ClientRouter extends AbstractRouter {
|
|
|
14
14
|
var _a;
|
|
15
15
|
const currentUrl = this.getCurrentUrl();
|
|
16
16
|
const { pathname, query } = this.resolveUrl({ url });
|
|
17
|
-
const isSameUrlNavigation = currentUrl.pathname === pathname;
|
|
17
|
+
const isSameUrlNavigation = (currentUrl ? currentUrl.pathname : window.location.pathname) === pathname;
|
|
18
|
+
const isUpdateCurrentRoute = type === 'updateCurrentRoute' || (!type && isSameUrlNavigation);
|
|
19
|
+
//
|
|
20
|
+
// When history was changed before rehydration, we need to pass this change if url is the same,
|
|
21
|
+
// because current route will be the same with any of this type changes, and while rehydration fresh url will be used.
|
|
22
|
+
// Another case is navigation, and it is okay to run `internalNavigate`, because we support this case before rehydration.
|
|
23
|
+
//
|
|
24
|
+
// @todo: find a better solution. We can monkeypatch window.history later, in `history.init` method,
|
|
25
|
+
// but it can lead to inconsistent state between current route and page url, if updated url is not the same.
|
|
26
|
+
//
|
|
27
|
+
if (isUpdateCurrentRoute && !currentUrl) {
|
|
28
|
+
if (replace) {
|
|
29
|
+
window.history.__originalHistory.replaceState(navigateState, '', url);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
window.history.__originalHistory.pushState(navigateState, '', url);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
18
36
|
if (type === 'updateCurrentRoute' || (!type && isSameUrlNavigation)) {
|
|
19
37
|
const route = (_a = this.tree) === null || _a === void 0 ? void 0 : _a.getRoute(pathname);
|
|
20
38
|
await this.internalUpdateCurrentRoute({
|
package/lib/router/client.es.js
CHANGED
|
@@ -14,7 +14,25 @@ class ClientRouter extends AbstractRouter {
|
|
|
14
14
|
var _a;
|
|
15
15
|
const currentUrl = this.getCurrentUrl();
|
|
16
16
|
const { pathname, query } = this.resolveUrl({ url });
|
|
17
|
-
const isSameUrlNavigation = currentUrl.pathname === pathname;
|
|
17
|
+
const isSameUrlNavigation = (currentUrl ? currentUrl.pathname : window.location.pathname) === pathname;
|
|
18
|
+
const isUpdateCurrentRoute = type === 'updateCurrentRoute' || (!type && isSameUrlNavigation);
|
|
19
|
+
//
|
|
20
|
+
// When history was changed before rehydration, we need to pass this change if url is the same,
|
|
21
|
+
// because current route will be the same with any of this type changes, and while rehydration fresh url will be used.
|
|
22
|
+
// Another case is navigation, and it is okay to run `internalNavigate`, because we support this case before rehydration.
|
|
23
|
+
//
|
|
24
|
+
// @todo: find a better solution. We can monkeypatch window.history later, in `history.init` method,
|
|
25
|
+
// but it can lead to inconsistent state between current route and page url, if updated url is not the same.
|
|
26
|
+
//
|
|
27
|
+
if (isUpdateCurrentRoute && !currentUrl) {
|
|
28
|
+
if (replace) {
|
|
29
|
+
window.history.__originalHistory.replaceState(navigateState, '', url);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
window.history.__originalHistory.pushState(navigateState, '', url);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
18
36
|
if (type === 'updateCurrentRoute' || (!type && isSameUrlNavigation)) {
|
|
19
37
|
const route = (_a = this.tree) === null || _a === void 0 ? void 0 : _a.getRoute(pathname);
|
|
20
38
|
await this.internalUpdateCurrentRoute({
|
package/lib/router/client.js
CHANGED
|
@@ -18,7 +18,25 @@ class ClientRouter extends abstract.AbstractRouter {
|
|
|
18
18
|
var _a;
|
|
19
19
|
const currentUrl = this.getCurrentUrl();
|
|
20
20
|
const { pathname, query } = this.resolveUrl({ url });
|
|
21
|
-
const isSameUrlNavigation = currentUrl.pathname === pathname;
|
|
21
|
+
const isSameUrlNavigation = (currentUrl ? currentUrl.pathname : window.location.pathname) === pathname;
|
|
22
|
+
const isUpdateCurrentRoute = type === 'updateCurrentRoute' || (!type && isSameUrlNavigation);
|
|
23
|
+
//
|
|
24
|
+
// When history was changed before rehydration, we need to pass this change if url is the same,
|
|
25
|
+
// because current route will be the same with any of this type changes, and while rehydration fresh url will be used.
|
|
26
|
+
// Another case is navigation, and it is okay to run `internalNavigate`, because we support this case before rehydration.
|
|
27
|
+
//
|
|
28
|
+
// @todo: find a better solution. We can monkeypatch window.history later, in `history.init` method,
|
|
29
|
+
// but it can lead to inconsistent state between current route and page url, if updated url is not the same.
|
|
30
|
+
//
|
|
31
|
+
if (isUpdateCurrentRoute && !currentUrl) {
|
|
32
|
+
if (replace) {
|
|
33
|
+
window.history.__originalHistory.replaceState(navigateState, '', url);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
window.history.__originalHistory.pushState(navigateState, '', url);
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
22
40
|
if (type === 'updateCurrentRoute' || (!type && isSameUrlNavigation)) {
|
|
23
41
|
const route = (_a = this.tree) === null || _a === void 0 ? void 0 : _a.getRoute(pathname);
|
|
24
42
|
await this.internalUpdateCurrentRoute({
|