@hybridly/core 0.1.0 → 0.2.1
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/dist/index.cjs +14 -2
- package/dist/index.mjs +14 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -214,6 +214,18 @@ function sameUrls(...hrefs) {
|
|
|
214
214
|
}
|
|
215
215
|
return false;
|
|
216
216
|
}
|
|
217
|
+
function sameHashes(...hrefs) {
|
|
218
|
+
if (hrefs.length < 2) {
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
return hrefs.every((href) => {
|
|
223
|
+
return makeUrl(href).toJSON() === makeUrl(hrefs.at(0)).toJSON();
|
|
224
|
+
});
|
|
225
|
+
} catch {
|
|
226
|
+
}
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
217
229
|
function fillHash(currentUrl, targetUrl) {
|
|
218
230
|
currentUrl = makeUrl(currentUrl);
|
|
219
231
|
targetUrl = makeUrl(targetUrl);
|
|
@@ -582,7 +594,7 @@ const router = {
|
|
|
582
594
|
abort: async () => getRouterContext().pendingNavigation?.controller.abort(),
|
|
583
595
|
active: () => !!getRouterContext().pendingNavigation,
|
|
584
596
|
navigate: async (options) => await performHybridNavigation(options),
|
|
585
|
-
reload: async (options) => await performHybridNavigation({ preserveScroll: true, preserveState: true, ...options }),
|
|
597
|
+
reload: async (options) => await performHybridNavigation({ preserveScroll: true, preserveState: true, replace: true, ...options }),
|
|
586
598
|
get: async (url, options = {}) => await performHybridNavigation({ ...options, url, method: "GET" }),
|
|
587
599
|
post: async (url, options = {}) => await performHybridNavigation({ preserveState: true, ...options, url, method: "POST" }),
|
|
588
600
|
put: async (url, options = {}) => await performHybridNavigation({ preserveState: true, ...options, url, method: "PUT" }),
|
|
@@ -714,7 +726,7 @@ async function performHybridNavigation(options) {
|
|
|
714
726
|
preserveScroll: options.preserveScroll,
|
|
715
727
|
preserveState: options.preserveState,
|
|
716
728
|
preserveUrl: options.preserveUrl,
|
|
717
|
-
replace: options.replace === true || options.preserveUrl
|
|
729
|
+
replace: options.replace === true || options.preserveUrl || sameUrls(payload.url, window.location.href) && !sameHashes(payload.url, window.location.href)
|
|
718
730
|
});
|
|
719
731
|
if (Object.keys(context.view.properties.errors ?? {}).length > 0) {
|
|
720
732
|
const errors = (() => {
|
package/dist/index.mjs
CHANGED
|
@@ -205,6 +205,18 @@ function sameUrls(...hrefs) {
|
|
|
205
205
|
}
|
|
206
206
|
return false;
|
|
207
207
|
}
|
|
208
|
+
function sameHashes(...hrefs) {
|
|
209
|
+
if (hrefs.length < 2) {
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
return hrefs.every((href) => {
|
|
214
|
+
return makeUrl(href).toJSON() === makeUrl(hrefs.at(0)).toJSON();
|
|
215
|
+
});
|
|
216
|
+
} catch {
|
|
217
|
+
}
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
208
220
|
function fillHash(currentUrl, targetUrl) {
|
|
209
221
|
currentUrl = makeUrl(currentUrl);
|
|
210
222
|
targetUrl = makeUrl(targetUrl);
|
|
@@ -573,7 +585,7 @@ const router = {
|
|
|
573
585
|
abort: async () => getRouterContext().pendingNavigation?.controller.abort(),
|
|
574
586
|
active: () => !!getRouterContext().pendingNavigation,
|
|
575
587
|
navigate: async (options) => await performHybridNavigation(options),
|
|
576
|
-
reload: async (options) => await performHybridNavigation({ preserveScroll: true, preserveState: true, ...options }),
|
|
588
|
+
reload: async (options) => await performHybridNavigation({ preserveScroll: true, preserveState: true, replace: true, ...options }),
|
|
577
589
|
get: async (url, options = {}) => await performHybridNavigation({ ...options, url, method: "GET" }),
|
|
578
590
|
post: async (url, options = {}) => await performHybridNavigation({ preserveState: true, ...options, url, method: "POST" }),
|
|
579
591
|
put: async (url, options = {}) => await performHybridNavigation({ preserveState: true, ...options, url, method: "PUT" }),
|
|
@@ -705,7 +717,7 @@ async function performHybridNavigation(options) {
|
|
|
705
717
|
preserveScroll: options.preserveScroll,
|
|
706
718
|
preserveState: options.preserveState,
|
|
707
719
|
preserveUrl: options.preserveUrl,
|
|
708
|
-
replace: options.replace === true || options.preserveUrl
|
|
720
|
+
replace: options.replace === true || options.preserveUrl || sameUrls(payload.url, window.location.href) && !sameHashes(payload.url, window.location.href)
|
|
709
721
|
});
|
|
710
722
|
if (Object.keys(context.view.properties.errors ?? {}).length > 0) {
|
|
711
723
|
const errors = (() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hybridly/core",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Core functionality of Hybridly",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hybridly",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"qs": "^6.11.1",
|
|
40
40
|
"superjson": "^1.12.2",
|
|
41
|
-
"@hybridly/utils": "0.1
|
|
41
|
+
"@hybridly/utils": "0.2.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"defu": "^6.1.2"
|