Skip to content

Commit 37cc67c

Browse files
authored
use fewer redirects (#18271)
1 parent 978a068 commit 37cc67c

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/Umbraco.Web.UI.Client/src/apps/backoffice/backoffice.context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class UmbBackofficeContext extends UmbContextBase<UmbBackofficeContext> {
4343
userContext.allowedSections,
4444
(allowedSections) => {
4545
if (!allowedSections) return;
46+
// TODO: Please be aware that we re-initialize this initializer based on user permissions. I suggest we should solve this specific case should be improved by the ability to change the filter [NL]
4647
new UmbExtensionsManifestInitializer(
4748
this,
4849
umbExtensionsRegistry,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export class UmbBackofficeMainElement extends UmbLitElement {
6767

6868
if (newRoutes.length > 0) {
6969
newRoutes.push({
70+
...newRoutes[0],
7071
path: ``,
71-
redirectTo: newRoutes[0].path,
7272
});
7373

7474
newRoutes.push({

src/Umbraco.Web.UI.Client/src/packages/core/section/section-main-views/section-main-views.element.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export class UmbSectionMainViewElement extends UmbLitElement {
2525
@state()
2626
private _activePath?: string;
2727

28+
@state()
29+
private _defaultView?: string;
30+
2831
@state()
2932
private _routes: Array<UmbRoute> = [];
3033

@@ -75,7 +78,11 @@ export class UmbSectionMainViewElement extends UmbLitElement {
7578

7679
const routes = [...dashboardRoutes, ...viewRoutes];
7780
if (routes.length > 0) {
78-
routes.push({ path: '', redirectTo: routes?.[0]?.path });
81+
this._defaultView = routes[0].path;
82+
routes.push({
83+
...routes[0],
84+
path: '',
85+
});
7986

8087
routes.push({
8188
path: `**`,
@@ -111,13 +118,16 @@ export class UmbSectionMainViewElement extends UmbLitElement {
111118
<uui-tab-group slot="header" id="dashboards">
112119
${this._dashboards.map((dashboard) => {
113120
const dashboardPath = this.#constructDashboardPath(dashboard);
121+
// If this path matches, or if this is the default view and the active path is empty.
122+
const isActive =
123+
this._activePath === dashboardPath || (this._defaultView === dashboardPath && this._activePath === '');
114124
return html`
115125
<uui-tab
116126
href="${this._routerPath}/${dashboardPath}"
117127
label="${dashboard.meta.label
118128
? this.localize.string(dashboard.meta.label)
119129
: (dashboard.name ?? dashboard.alias)}"
120-
?active="${this._activePath === dashboardPath}"></uui-tab>
130+
?active="${isActive}"></uui-tab>
121131
`;
122132
})}
123133
</uui-tab-group>
@@ -133,11 +143,11 @@ export class UmbSectionMainViewElement extends UmbLitElement {
133143
${this._views.map((view) => {
134144
const viewName = view.meta.label ? this.localize.string(view.meta.label) : (view.name ?? view.alias);
135145
const viewPath = this.#constructViewPath(view);
146+
// If this path matches, or if this is the default view and the active path is empty.
147+
const isActive =
148+
this._activePath === viewPath || (this._defaultView === viewPath && this._activePath === '');
136149
return html`
137-
<uui-tab
138-
href="${this._routerPath}/${viewPath}"
139-
label="${viewName}"
140-
?active="${this._activePath === viewPath}">
150+
<uui-tab href="${this._routerPath}/${viewPath}" label="${viewName}" ?active="${isActive}">
141151
<umb-icon slot="icon" name=${view.meta.icon}></umb-icon>
142152
${viewName}
143153
</uui-tab>

0 commit comments

Comments
 (0)