Skip to content

Commit f03a7d3

Browse files
Introduce delay and expand path matching on Backoffice router for lazy-loaded routes (#19409)
* implement use of pathMatch: 'full' for empty redirects * awaitStability feature for route redirects --------- Co-authored-by: Jacob Overgaard <[email protected]>
1 parent 86bbdfe commit f03a7d3

File tree

13 files changed

+43
-1
lines changed

13 files changed

+43
-1
lines changed

src/Umbraco.Web.UI.Client/examples/modal-routed/dashboard.element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class UmbDashboardElement extends UmbElementMixin(LitElement) {
1717
},
1818
{
1919
path: '',
20+
pathMatch: 'full',
2021
redirectTo: 'tab1',
2122
},
2223
];

src/Umbraco.Web.UI.Client/examples/modal-routed/modal/example-modal.element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class UmbExampleModal extends UmbModalBaseElement {
1717
},
1818
{
1919
path: '',
20+
pathMatch: 'full',
2021
redirectTo: 'modalOverview',
2122
},
2223
];

src/Umbraco.Web.UI.Client/src/apps/backoffice/components/backoffice-main.element.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ export class UmbBackofficeMainElement extends UmbLitElement {
6363

6464
if (newRoutes.length > 0) {
6565
newRoutes.push({
66+
path: '',
67+
pathMatch: 'full',
68+
awaitStability: true,
6669
redirectTo: newRoutes[0].path,
67-
path: ``,
6870
});
6971

7072
newRoutes.push({

src/Umbraco.Web.UI.Client/src/packages/block/block/workspace/views/edit/block-workspace-view-edit.element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export class UmbBlockWorkspaceViewEditElement extends UmbLitElement implements U
123123
if (!this._hasRootGroups) {
124124
routes.push({
125125
path: '',
126+
pathMatch: 'full',
126127
redirectTo: routes[0]?.path,
127128
});
128129
}

src/Umbraco.Web.UI.Client/src/packages/content/content-type/workspace/views/design/content-type-design-editor.element.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,14 @@ export class UmbContentTypeDesignEditorElement extends UmbLitElement implements
205205
});
206206
routes.push({
207207
path: '',
208+
pathMatch: 'full',
208209
redirectTo: 'root',
209210
guards: [() => this.#processingTabId === undefined],
210211
});
211212
} else {
212213
routes.push({
213214
path: '',
215+
pathMatch: 'full',
214216
redirectTo: routes[0]?.path,
215217
guards: [() => this.#processingTabId === undefined],
216218
});

src/Umbraco.Web.UI.Client/src/packages/content/content/workspace/views/edit/content-editor.element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export class UmbContentWorkspaceViewEditElement extends UmbLitElement implements
109109
if (routes.length !== 0) {
110110
routes.push({
111111
path: '',
112+
pathMatch: 'full',
112113
redirectTo: routes[0].path,
113114
});
114115

src/Umbraco.Web.UI.Client/src/packages/core/router/router-slot/model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ export interface IRedirectRoute<D = any> extends IRouteBase<D> {
7575
// The paths the route should redirect to. Can either be relative or absolute.
7676
redirectTo: string;
7777

78+
// First redirect when the routes appears stable. Delaying the redirect so other routes get the change to resolve first.
79+
awaitStability?: boolean;
80+
7881
// Whether the query should be preserved when redirecting.
7982
preserveQuery?: boolean;
8083
}

src/Umbraco.Web.UI.Client/src/packages/core/router/router-slot/router-slot.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,24 @@ export class RouterSlot<D = any, P = any> extends HTMLElement implements IRouter
314314
}
315315
}
316316

317+
private getRedirectDelay() {
318+
if ('connection' in navigator) {
319+
const connection =
320+
navigator.connection || (navigator as any).mozConnection || (navigator as any).webkitConnection;
321+
322+
switch (connection.effectiveType) {
323+
case 'slow-2g':
324+
case '2g':
325+
return 1200;
326+
case '3g':
327+
return 800;
328+
case '4g':
329+
return 200;
330+
}
331+
}
332+
return 400;
333+
}
334+
317335
/**
318336
* Loads a new path based on the routes.
319337
* Returns true if a navigation was made to a new page.
@@ -387,6 +405,14 @@ export class RouterSlot<D = any, P = any> extends HTMLElement implements IRouter
387405
// Redirect if necessary
388406
if (isRedirectRoute(route)) {
389407
cleanup();
408+
if (route.awaitStability === true) {
409+
// await until browser is done loading, based on a guess:
410+
const delay = this.getRedirectDelay();
411+
await new Promise((resolve) => setTimeout(resolve, delay));
412+
if (navigationInvalidated) {
413+
return cancel();
414+
}
415+
}
390416
handleRedirect(this, route);
391417
return false;
392418
}

src/Umbraco.Web.UI.Client/src/packages/documents/document-blueprints/workspace/document-blueprint-workspace-editor.element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class UmbDocumentBlueprintWorkspaceEditorElement extends UmbLitElement {
7979
// Using first single view as the default route for now (hence the math below):
8080
routes.push({
8181
path: '',
82+
pathMatch: 'full',
8283
redirectTo: routes[variants.length * variants.length]?.path,
8384
});
8485
}

src/Umbraco.Web.UI.Client/src/packages/media/media/dashboard/media-dashboard.element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export class UmbMediaDashboardElement extends UmbLitElement {
5353
},
5454
{
5555
path: '',
56+
pathMatch: 'full',
5657
redirectTo: 'collection',
5758
},
5859
{

src/Umbraco.Web.UI.Client/src/packages/media/media/workspace/media-workspace-editor.element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class UmbMediaWorkspaceEditorElement extends UmbLitElement {
7979
// Using first single view as the default route for now (hence the math below):
8080
routes.push({
8181
path: '',
82+
pathMatch: 'full',
8283
redirectTo: routes[variants.length * variants.length]?.path,
8384
});
8485
}

src/Umbraco.Web.UI.Client/src/packages/members/member/workspace/member/member-workspace-editor.element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export class UmbMemberWorkspaceEditorElement extends UmbLitElement {
8181
// Using first single view as the default route for now (hence the math below):
8282
routes.push({
8383
path: '',
84+
pathMatch: 'full',
8485
redirectTo: routes[options.length * options.length]?.path,
8586
});
8687
}

src/Umbraco.Web.UI.Client/src/packages/packages/package-section/views/created/created-packages-section-view.element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class UmbCreatedPackagesSectionViewElement extends UmbLitElement implemen
5454

5555
routes.push({
5656
path: '',
57+
pathMatch: 'full',
5758
redirectTo: 'overview',
5859
});
5960
routes.push({

0 commit comments

Comments
 (0)