@thepassle/app-tools 0.9.6 → 0.9.7

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 +17 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thepassle/app-tools",
3
- "version": "0.9.6",
3
+ "version": "0.9.7",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "scripts": {
package/router/index.js CHANGED
@@ -81,7 +81,7 @@ export class Router extends EventTarget {
81
81
  * @template RenderResult
82
82
  */
83
83
  render() {
84
- log(`Rendering route ${this.context.url.pathname}${this.context.url.search}`, { context: this.context, route: this.route });
84
+ log(`Rendering route ${this.context.url.pathname}${this.context.url.search}${this.context.url.hash}`, { context: this.context, route: this.route });
85
85
  return /** @type {RenderResult} */ (this.route?.render?.(this.context));
86
86
  }
87
87
 
@@ -106,7 +106,7 @@ export class Router extends EventTarget {
106
106
  return route;
107
107
  }
108
108
  }
109
- log(`No route matched for ${url.pathname}${url.search}`, url);
109
+ log(`No route matched for ${url.pathname}${url.search}${url.hash}`, url);
110
110
  return null;
111
111
  }
112
112
 
@@ -154,6 +154,13 @@ export class Router extends EventTarget {
154
154
  this.navigate(url);
155
155
  }
156
156
 
157
+ _collectPlugins(route) {
158
+ return [
159
+ ...(this.config?.plugins ?? []),
160
+ ...(route?.plugins ?? []),
161
+ ]
162
+ }
163
+
157
164
  /**
158
165
  * @param {string | URL} url The URL to navigate to.
159
166
  * @param {{
@@ -165,14 +172,11 @@ export class Router extends EventTarget {
165
172
  url = new URL(url, this.baseUrl);
166
173
  }
167
174
 
168
- this.route = this._matchRoute(url) || this._matchRoute(this.fallback);
169
- log(`Navigating to ${url.pathname}${url.search}`, { context: this.context, route: this.route });
175
+ let route = this._matchRoute(url) || this._matchRoute(this.fallback);
176
+ log(`Navigating to ${url.pathname}${url.search}${url.hash}`, { context: this.context, route: this.route });
170
177
 
171
178
  /** @type {Plugin[]} */
172
- const plugins = [
173
- ...(this.config?.plugins ?? []),
174
- ...(this.route?.plugins ?? []),
175
- ];
179
+ let plugins = this._collectPlugins(route);
176
180
 
177
181
  for (const plugin of plugins) {
178
182
  try {
@@ -181,7 +185,8 @@ export class Router extends EventTarget {
181
185
  const condition = await result.condition();
182
186
  if (!condition) {
183
187
  url = new URL(result.redirect, this.baseUrl);
184
- this.route = this._matchRoute(url) || this._matchRoute(this.fallback);
188
+ route = this._matchRoute(url) || this._matchRoute(this.fallback);
189
+ plugins = this._collectPlugins(route);
185
190
  log('Redirecting', { context: this.context, route: this.route });
186
191
  }
187
192
  }
@@ -191,6 +196,8 @@ export class Router extends EventTarget {
191
196
  }
192
197
  }
193
198
 
199
+ this.route = route;
200
+
194
201
  if (!this.route) {
195
202
  throw new Error(`[ROUTER] No route or fallback matched for url ${url}`);
196
203
  }
@@ -205,7 +212,7 @@ export class Router extends EventTarget {
205
212
  }
206
213
 
207
214
  if (!options.backNav) {
208
- window.history.pushState(null, '', `${url.pathname}${url.search}`);
215
+ window.history.pushState(null, '', `${url.pathname}${url.search}${url.hash}`);
209
216
  }
210
217
  document.title = this.context.title;
211
218
  this._notifyUrlChanged();