Skip to content

Commit 3b6be8e

Browse files
Feature: Redirect to the last visited path when navigating between sections (#20084)
* redirect to the last visited path in a section * Update src/Umbraco.Web.UI.Client/src/apps/backoffice/components/backoffice-header-sections.element.ts Co-authored-by: Copilot <[email protected]> * Update backoffice-header-sections.element.ts --------- Co-authored-by: Copilot <[email protected]>
1 parent 88dd30b commit 3b6be8e

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export class UmbBackofficeHeaderSectionsElement extends UmbLitElement {
1616

1717
private _backofficeContext?: UmbBackofficeContext;
1818

19+
#sectionPathMap = new Map<string, string>();
20+
1921
constructor() {
2022
super();
2123

@@ -52,6 +54,42 @@ export class UmbBackofficeHeaderSectionsElement extends UmbLitElement {
5254
);
5355
}
5456

57+
#getSectionPath(manifest: ManifestSection | undefined) {
58+
return `section/${manifest?.meta.pathname}`;
59+
}
60+
61+
#onSectionClick(event: PointerEvent, manifest: ManifestSection | undefined) {
62+
// Let the browser handle the click if the Ctrl or Meta key is pressed
63+
if (event.ctrlKey || event.metaKey) {
64+
return;
65+
}
66+
67+
event.stopPropagation();
68+
event.preventDefault();
69+
70+
// Store the current path for the section so we can redirect to it next time the section is visited
71+
if (this._currentSectionAlias) {
72+
const currentPath = window.location.pathname;
73+
this.#sectionPathMap.set(this._currentSectionAlias, currentPath);
74+
}
75+
76+
if (!manifest) {
77+
throw new Error('Section manifest is missing');
78+
}
79+
80+
const clickedSectionAlias = manifest.alias;
81+
82+
// Check if we have a stored path for the clicked section
83+
if (this.#sectionPathMap.has(clickedSectionAlias)) {
84+
const storedPath = this.#sectionPathMap.get(clickedSectionAlias);
85+
history.pushState(null, '', storedPath);
86+
} else {
87+
// Nothing stored, so we navigate to the regular section path
88+
const sectionPath = this.#getSectionPath(manifest);
89+
history.pushState(null, '', sectionPath);
90+
}
91+
}
92+
5593
override render() {
5694
return html`
5795
<uui-tab-group id="tabs" data-mark="section-links">
@@ -61,7 +99,8 @@ export class UmbBackofficeHeaderSectionsElement extends UmbLitElement {
6199
(section) => html`
62100
<uui-tab
63101
?active="${this._currentSectionAlias === section.alias}"
64-
href="${`section/${section.manifest?.meta.pathname}`}"
102+
@click=${(event: PointerEvent) => this.#onSectionClick(event, section.manifest)}
103+
href="${this.#getSectionPath(section.manifest)}"
65104
label="${ifDefined(
66105
section.manifest?.meta.label
67106
? this.localize.string(section.manifest?.meta.label)

0 commit comments

Comments
 (0)