saasufy-components 3.8.0 → 3.9.0
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/README.md +3 -0
- package/app-router.js +18 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -146,9 +146,12 @@ So for example, if your `index.html` file is served up from the URL `http://mywe
|
|
|
146
146
|
|
|
147
147
|
- `default-page`: The path/route of the default page to send the user to in case no routes are matched. Commonly used to point to a `/page-not-found` page. For the home page, it's typically recommended to create a page template with `route-path=""` instead.
|
|
148
148
|
- `debounce-delay`: The number of milliseconds to wait before changing the route. This can help to avoid multiple renders if the route changes rapidly (e.g. when doing hard redirects). Defaults to 100ms.
|
|
149
|
+
- `target-page`: A convenience attribute which can be used to programmatically change the `location.hash` in the address bar.
|
|
149
150
|
|
|
150
151
|
**Attributes of slotted page templates**
|
|
151
152
|
|
|
153
|
+
- `route-path`: The path of the page. Supports custom URL parameters in the format `/org/:orgId/user/:userId`.
|
|
154
|
+
- `partial-route`: An optional attribute which, if specified, will allow the `route-path` to be matched partially from the start. This can be used to ignore the ending of a path which is not relevant to the page in order to avoid unnecessary re-renders.
|
|
152
155
|
- `redirect`: An optional path/route which this page should redirect to. Note that the content of this page will not be shown so it should always be empty.
|
|
153
156
|
- `auth-redirect`: An optional path/route which this page should redirect to if the user is authenticated. If the user is not authenticated, then the content of the template will be displayed as normal.
|
|
154
157
|
- `no-auth-redirect`: An optional path/route which this page should redirect to if the user is not authenticated. If the user is authenticated, then the content of the template will be displayed as normal.
|
package/app-router.js
CHANGED
|
@@ -14,6 +14,7 @@ export class AppRouter extends SocketConsumer {
|
|
|
14
14
|
this.pageRouteInfos = [];
|
|
15
15
|
this.debounce = debouncer();
|
|
16
16
|
this.debounceDelay = DEFAULT_DEBOUNCE_DELAY;
|
|
17
|
+
this.lastPageState = null;
|
|
17
18
|
|
|
18
19
|
this.hashStartRegex = /^#/;
|
|
19
20
|
|
|
@@ -30,12 +31,15 @@ export class AppRouter extends SocketConsumer {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
this.pageRouteInfos = Object.keys(this.pages).map((route) => {
|
|
34
|
+
let pageTemplate = this.pages[route];
|
|
35
|
+
let allowPartialMatch = pageTemplate.hasAttribute('partial-route');
|
|
33
36
|
return {
|
|
34
|
-
regExp: new RegExp(`^${route.replace(/\/:[^\/]+/g, '/([^/]*)').replace(/\//g, '\\/')}
|
|
37
|
+
regExp: new RegExp(`^${route.replace(/\/:[^\/]+/g, '/([^/]*)').replace(/\//g, '\\/')}${allowPartialMatch ? '' : '$'}`, 'g'),
|
|
35
38
|
route,
|
|
36
39
|
params: [ ...route.matchAll(/:[^\/]*/g) ].map(paramMatch => paramMatch[0].replace(':', ''))
|
|
37
40
|
};
|
|
38
41
|
});
|
|
42
|
+
|
|
39
43
|
if (!this.socket || this.socket.state === this.socket.OPEN) {
|
|
40
44
|
this.debounce(this.renderCurrentPage, this.debounceDelay);
|
|
41
45
|
}
|
|
@@ -52,6 +56,7 @@ export class AppRouter extends SocketConsumer {
|
|
|
52
56
|
|
|
53
57
|
static get observedAttributes() {
|
|
54
58
|
return [
|
|
59
|
+
'target-page',
|
|
55
60
|
'default-page',
|
|
56
61
|
'debounce-delay',
|
|
57
62
|
'max-redirects'
|
|
@@ -65,6 +70,8 @@ export class AppRouter extends SocketConsumer {
|
|
|
65
70
|
} else {
|
|
66
71
|
this.debounceDelay = DEFAULT_DEBOUNCE_DELAY;
|
|
67
72
|
}
|
|
73
|
+
} else if (name === 'target-page') {
|
|
74
|
+
location.hash = newValue;
|
|
68
75
|
} else if (this.isReady) {
|
|
69
76
|
this.renderCurrentPage();
|
|
70
77
|
}
|
|
@@ -225,6 +232,16 @@ export class AppRouter extends SocketConsumer {
|
|
|
225
232
|
routeArgs = {};
|
|
226
233
|
}
|
|
227
234
|
|
|
235
|
+
|
|
236
|
+
let pageState = JSON.stringify({
|
|
237
|
+
route,
|
|
238
|
+
routeArgs
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
if (pageState === this.lastPageState) return;
|
|
242
|
+
|
|
243
|
+
this.lastPageState = pageState;
|
|
244
|
+
|
|
228
245
|
routerViewport.innerHTML = renderTemplate(
|
|
229
246
|
pageTemplate.innerHTML,
|
|
230
247
|
routeArgs,
|