@thepassle/app-tools 0.9.10 → 0.9.12
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/package.json +1 -1
- package/router/index.js +7 -3
- package/router/plugins/offline.js +2 -2
package/package.json
CHANGED
package/router/index.js
CHANGED
|
@@ -51,7 +51,7 @@ export class Router extends EventTarget {
|
|
|
51
51
|
log('Initialized routes', this.routes);
|
|
52
52
|
|
|
53
53
|
queueMicrotask(() => {
|
|
54
|
-
this.navigate(new URL(window.location.href));
|
|
54
|
+
this.navigate(new URL(window.location.href), { replace: true });
|
|
55
55
|
});
|
|
56
56
|
window.addEventListener('popstate', this._onPopState);
|
|
57
57
|
window.addEventListener('click', this._onAnchorClick);
|
|
@@ -167,7 +167,8 @@ export class Router extends EventTarget {
|
|
|
167
167
|
/**
|
|
168
168
|
* @param {string | URL} url The URL to navigate to.
|
|
169
169
|
* @param {{
|
|
170
|
-
* backNav?: boolean
|
|
170
|
+
* backNav?: boolean,
|
|
171
|
+
* replace?: boolean,
|
|
171
172
|
* }} options options An options object to configure the navigation. The backNav property specifies whether the navigation is a backward navigation, which doesn't push the navigation into browser nav history.
|
|
172
173
|
*/
|
|
173
174
|
async navigate(url, options = {}) {
|
|
@@ -214,9 +215,12 @@ export class Router extends EventTarget {
|
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
|
|
217
|
-
if (
|
|
218
|
+
if (options?.replace) {
|
|
219
|
+
window.history.replaceState(null, '', `${url.pathname}${url.search}${url.hash}`);
|
|
220
|
+
} else if (!options.backNav) {
|
|
218
221
|
window.history.pushState(null, '', `${url.pathname}${url.search}${url.hash}`);
|
|
219
222
|
}
|
|
223
|
+
|
|
220
224
|
document.title = this.context.title;
|
|
221
225
|
this._notifyUrlChanged();
|
|
222
226
|
|
|
@@ -7,10 +7,10 @@ export function offlinePlugin(offlineRoute = '/offline') {
|
|
|
7
7
|
return {
|
|
8
8
|
name: 'offline',
|
|
9
9
|
shouldNavigate: () => ({
|
|
10
|
-
condition: () =>
|
|
10
|
+
condition: () => navigator.onLine,
|
|
11
11
|
redirect: offlineRoute,
|
|
12
12
|
})
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export const offline = offlinePlugin();
|
|
16
|
+
export const offline = offlinePlugin();
|