@thepassle/app-tools 0.9.10 → 0.9.11

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/router/index.js +7 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thepassle/app-tools",
3
- "version": "0.9.10",
3
+ "version": "0.9.11",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "scripts": {
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 (!options.backNav) {
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