@brightspace-ui/labs 2.33.1 → 2.34.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/package.json
CHANGED
|
@@ -222,31 +222,6 @@ describe('Page Routing', () => {
|
|
|
222
222
|
|
|
223
223
|
### Route order inversion issue
|
|
224
224
|
|
|
225
|
-
|
|
225
|
+
This issue is resolved by default but the fix can be bypassed (for backwards compatibility) by setting the `disableRouteOrderFix` option to `true`.
|
|
226
226
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
#### Issue Fix
|
|
230
|
-
|
|
231
|
-
There is currently a fix available for this ordering issue, but it requires setting the `enableRouteOrderFix` option to `true`. Ex:
|
|
232
|
-
|
|
233
|
-
```js
|
|
234
|
-
registerRoutes([
|
|
235
|
-
{
|
|
236
|
-
pattern: '/home',
|
|
237
|
-
view: () => html`...`
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
pattern: '/404',
|
|
241
|
-
view: () => html`...`
|
|
242
|
-
},
|
|
243
|
-
{
|
|
244
|
-
pattern: '*',
|
|
245
|
-
to: '/404'
|
|
246
|
-
}
|
|
247
|
-
], {
|
|
248
|
-
enableRouteOrderFix: true
|
|
249
|
-
});
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
Note: The reason this is an opt-in fix is that a lot of existing implementations of lit-router have worked around this issue by putting the wildcard routes at the start, which would break if the issue were fixed for everyone automatically.
|
|
227
|
+
Bypassing the fix causes a warning to appear in the dev console. To resolve the warning, remove the `disaableRouteOrderFix` option and thoroughly test your routing. If your routes contain wildcards (`*`, typically for 404s), you may need to register them last.
|
|
@@ -38,10 +38,10 @@ const _handleRouteView = (context, next, r) => {
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
const _handleRouteLoader = r => (context, next) => {
|
|
41
|
-
const
|
|
41
|
+
const disableRouteOrderFix = _lastOptions?.disableRouteOrderFix ?? false;
|
|
42
42
|
|
|
43
43
|
// Skip further pattern matches if the route has already been handled
|
|
44
|
-
if (
|
|
44
|
+
if (!disableRouteOrderFix && context.handled) {
|
|
45
45
|
next();
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
@@ -51,7 +51,7 @@ const _handleRouteLoader = r => (context, next) => {
|
|
|
51
51
|
_handleRouteView(context, next, r);
|
|
52
52
|
});
|
|
53
53
|
} else if (r.pattern && r.to) {
|
|
54
|
-
if (
|
|
54
|
+
if (!disableRouteOrderFix) {
|
|
55
55
|
activePage.redirect(r.to);
|
|
56
56
|
} else {
|
|
57
57
|
activePage.redirect(r.pattern, r.to);
|
|
@@ -93,7 +93,7 @@ export const registerRoutes = (routes, options) => {
|
|
|
93
93
|
if (hasRegistered) throw new Error('May not construct multiple routers.');
|
|
94
94
|
hasRegistered = true;
|
|
95
95
|
|
|
96
|
-
if (
|
|
96
|
+
if (options?.disableRouteOrderFix) console.warn('lit-router: The disableRouteOrderFix option is enabled, which may cause issues with route handling. See here for details: https://github.com/BrightspaceUI/labs/tree/main/src/utilities/router#route-order-inversion-issue');
|
|
97
97
|
|
|
98
98
|
configure(options);
|
|
99
99
|
|