@thepassle/app-tools 0.8.7 → 0.8.9

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 +13 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thepassle/app-tools",
3
- "version": "0.8.7",
3
+ "version": "0.8.9",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "scripts": {
package/router/index.js CHANGED
@@ -106,7 +106,7 @@ export class Router extends EventTarget {
106
106
  }
107
107
 
108
108
  _onPopState = () => {
109
- this.navigate(new URL(window.location.href));
109
+ this.navigate(new URL(window.location.href), { backNav: true });
110
110
  }
111
111
 
112
112
  _onAnchorClick = (e) => {
@@ -126,6 +126,7 @@ export class Router extends EventTarget {
126
126
  const url = new URL(a.href);
127
127
 
128
128
  if (this.url.href === url.href) return;
129
+ if (url.host !== window.location.host) return;
129
130
  if (a.hasAttribute('download') || a.href.includes('mailto:')) return;
130
131
 
131
132
  const target = a.getAttribute('target');
@@ -136,12 +137,16 @@ export class Router extends EventTarget {
136
137
  }
137
138
 
138
139
  /**
139
- * @param {string | URL} url
140
+ * @param {string | URL} url The URL to navigate to.
141
+ * @param {@param {{
142
+ * backNav?: boolean
143
+ * }} 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.
140
144
  */
141
- async navigate(url) {
145
+ async navigate(url, options = {}) {
142
146
  if (typeof url === 'string') {
143
147
  url = new URL(url, this.baseUrl);
144
- }
148
+ }
149
+
145
150
  this.route = this._matchRoute(url) || this._matchRoute(this.fallback);
146
151
  log(`Navigating to ${url.pathname}${url.search}`, { context: this.context, route: this.route });
147
152
 
@@ -181,7 +186,9 @@ export class Router extends EventTarget {
181
186
  }
182
187
  }
183
188
 
184
- window.history.pushState(null, '', `${url.pathname}${url.search}`);
189
+ if (!options.backNav) {
190
+ window.history.pushState(null, '', `${url.pathname}${url.search}`);
191
+ }
185
192
  document.title = this.context.title;
186
193
  this._notifyUrlChanged();
187
194
 
@@ -194,4 +201,4 @@ export class Router extends EventTarget {
194
201
  }
195
202
  }
196
203
  }
197
- }
204
+ }