-
- {{ ARROW_BACK_ICON }}
- Alle Patente
-
-
@if (loading) {
- @if (showDetail && selectedPatent) {
-
- ← Zurück zu den Patenten
-
- }
-
@if (error) {
Fehler beim Laden der Patente.
} @else if (showDetail && selectedPatent) {
diff --git a/webapp/src/app/modules/patents/patents.component.ts b/webapp/src/app/modules/patents/patents.component.ts
index 758f23ca..a60446e1 100644
--- a/webapp/src/app/modules/patents/patents.component.ts
+++ b/webapp/src/app/modules/patents/patents.component.ts
@@ -24,6 +24,7 @@ import {
import { FilterCardComponent } from '../../shared/ui/filter-card/filter-card.component';
import { HELP_ICON, PATENT_ICON } from '../../shared/ui/icons';
import { PageContainerComponent } from '../../shared/ui/page-container/page-container.component';
+import { BackNavigationService } from '../../shared/services/back-navigation.service';
type PatentSource = 'EPO' | 'USPTO';
@@ -69,6 +70,8 @@ export class PatentsComponent {
private route = inject(ActivatedRoute);
private patentsApi = inject(PatentsService);
private destroyRef = inject(DestroyRef);
+ private backNavigation = inject(BackNavigationService);
+ private unregisterLocalBack: (() => void) | null = null;
patents: PatentEntry[] = [];
total = 0;
@@ -92,6 +95,8 @@ export class PatentsComponent {
readonly expandedClassificationKeys = new Set();
constructor() {
+ this.destroyRef.onDestroy(() => this.unregisterLocalBack?.());
+
this.route.queryParams
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((qp) => {
@@ -181,12 +186,20 @@ export class PatentsComponent {
}
selectPatent(patent: PatentEntry): void {
+ this.unregisterLocalBack?.();
+ this.unregisterLocalBack = this.backNavigation.registerLocalBack(() =>
+ this.closeDetail(),
+ );
+
this.selectedPatent = patent;
this.showDetail = true;
this.expandedClassificationKeys.clear();
}
closeDetail(): void {
+ this.unregisterLocalBack?.();
+ this.unregisterLocalBack = null;
+
this.showDetail = false;
this.selectedPatent = null;
this.expandedClassificationKeys.clear();
diff --git a/webapp/src/app/modules/projects/bund-details/bund-details.component.ts b/webapp/src/app/modules/projects/bund-details/bund-details.component.ts
index ed0573df..f0e362dd 100644
--- a/webapp/src/app/modules/projects/bund-details/bund-details.component.ts
+++ b/webapp/src/app/modules/projects/bund-details/bund-details.component.ts
@@ -172,7 +172,4 @@ export class BundDetailsComponent implements OnInit {
return 'var(--sg-text-muted)';
}
}
- goBack(): void {
- window.history.back();
- }
}
diff --git a/webapp/src/app/modules/projects/dfg-details/dfg-details.component.ts b/webapp/src/app/modules/projects/dfg-details/dfg-details.component.ts
index 7e66404c..3f1c6271 100644
--- a/webapp/src/app/modules/projects/dfg-details/dfg-details.component.ts
+++ b/webapp/src/app/modules/projects/dfg-details/dfg-details.component.ts
@@ -279,8 +279,4 @@ export class DfgDetailsComponent implements OnInit {
queryParams: { search: institutionName },
});
}
-
- goBack(): void {
- window.history.back();
- }
}
diff --git a/webapp/src/app/modules/publication-detail/publication-detail.component.html b/webapp/src/app/modules/publication-detail/publication-detail.component.html
index 5daa523b..0303ab56 100644
--- a/webapp/src/app/modules/publication-detail/publication-detail.component.html
+++ b/webapp/src/app/modules/publication-detail/publication-detail.component.html
@@ -1,14 +1,5 @@
-
- {{ ARROW_BACK_ICON }}
- {{ returnLabel }}
-
-
@if (loading) {
();
@@ -130,20 +130,22 @@ export class PublicationDetailComponent implements OnInit {
readonly institutionsPageSize = 5;
returnUrl: string | null = null;
- returnLabel = 'Alle Publikationen';
- returnAriaLabel = 'Zurück zu den Publikationen';
ngOnInit(): void {
this.loading = true;
const navigationState = this.location.getState() as {
returnUrl?: string;
- returnLabel?: string;
} | null;
if (navigationState?.returnUrl) {
this.returnUrl = navigationState.returnUrl;
- this.returnLabel = navigationState.returnLabel ?? 'Zurück';
- this.returnAriaLabel = `Zurück zu ${this.returnLabel}`;
+
+ // The topbar back button should return to the page the user came from,
+ // not to an unrelated history entry.
+ const unregister = this.backNavigation.registerLocalBack(() =>
+ this.navigateBack(),
+ );
+ this.destroyRef.onDestroy(unregister);
}
this.route.data.pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
diff --git a/webapp/src/app/shared/services/back-navigation.service.ts b/webapp/src/app/shared/services/back-navigation.service.ts
new file mode 100644
index 00000000..5b3162d9
--- /dev/null
+++ b/webapp/src/app/shared/services/back-navigation.service.ts
@@ -0,0 +1,114 @@
+import { Location } from '@angular/common';
+import { Injectable, computed, inject, signal } from '@angular/core';
+import { Router } from '@angular/router';
+
+type BackHandler = () => void;
+
+const ROOT_PATHS = new Set([
+ '/dashboard',
+ '/compare',
+ '/multipliers',
+ '/founders',
+ '/bookmarks',
+ '/persons',
+ '/keywords',
+ '/hierarchy',
+ '/news',
+ '/account',
+ '/accounts',
+ '/organizations',
+ '/jobs',
+ '/publications',
+ '/topics',
+ '/projects',
+ '/patents',
+ '/institutions',
+ '/login',
+ '/forgot-password',
+ '/reset-password',
+ '/icons',
+ '/error',
+]);
+
+const FALLBACKS: ReadonlyArray<{ prefix: string; target: string }> = [
+ { prefix: '/person/', target: '/persons' },
+ { prefix: '/publication/', target: '/publications' },
+ { prefix: '/patent/', target: '/patents' },
+ { prefix: '/news/', target: '/news' },
+ { prefix: '/institution/', target: '/institutions' },
+ { prefix: '/topic/', target: '/topics' },
+ { prefix: '/projects/', target: '/projects' },
+ { prefix: '/founders/', target: '/multipliers' },
+ { prefix: '/keywords/', target: '/keywords' },
+ { prefix: '/error', target: '/dashboard' },
+];
+
+@Injectable({ providedIn: 'root' })
+export class BackNavigationService {
+ private readonly router = inject(Router);
+ private readonly location = inject(Location);
+
+ // In-page detail views (e.g. the inline patent detail) own the back action
+ // while they are open. The topbar button executes the newest handler.
+ private readonly localHandlers = signal([]);
+
+ readonly hasLocalHandler = computed(() => this.localHandlers().length > 0);
+
+ /**
+ * Registers a back action for an in-page detail view. Returns an unregister
+ * function that the component calls when the view closes or is destroyed.
+ */
+ registerLocalBack(handler: BackHandler): () => void {
+ this.localHandlers.update((handlers) => [...handlers, handler]);
+
+ return () => {
+ this.localHandlers.update((handlers) =>
+ handlers.filter((candidate) => candidate !== handler),
+ );
+ };
+ }
+
+ /** True when this tab has at least one earlier in-app navigation. */
+ canGoBack(): boolean {
+ const state = history.state as { navigationId?: number } | null;
+ return (state?.navigationId ?? 0) > 1;
+ }
+
+ /**
+ * Goes back in history when that is safe, otherwise navigates to the
+ * section that owns the current detail page.
+ */
+ back(fallback?: string): void {
+ const handlers = this.localHandlers();
+ const localHandler = handlers[handlers.length - 1];
+
+ if (localHandler) {
+ localHandler();
+ return;
+ }
+
+ if (this.canGoBack()) {
+ this.location.back();
+ return;
+ }
+
+ void this.router.navigateByUrl(
+ fallback ?? this.fallbackFor(this.router.url),
+ );
+ }
+
+ /** Whether the current URL is a top-level section. */
+ isRoot(url: string): boolean {
+ return ROOT_PATHS.has(this.pathOf(url));
+ }
+
+ fallbackFor(url: string): string {
+ const path = this.pathOf(url);
+ const match = FALLBACKS.find(({ prefix }) => path.startsWith(prefix));
+ return match?.target ?? '/dashboard';
+ }
+
+ private pathOf(url: string): string {
+ return url.split('?')[0].split('#')[0] || '/';
+ }
+}
diff --git a/webapp/src/app/shared/ui/app-layout/app-layout.component.ts b/webapp/src/app/shared/ui/app-layout/app-layout.component.ts
index 00cfea1d..7f47cb21 100644
--- a/webapp/src/app/shared/ui/app-layout/app-layout.component.ts
+++ b/webapp/src/app/shared/ui/app-layout/app-layout.component.ts
@@ -93,7 +93,9 @@ export class AppLayoutComponent implements OnInit, OnDestroy {
private readonly currentPath = signal('/');
readonly showBack = computed(
- () => !this.backNavigation.isRoot(this.currentPath()),
+ () =>
+ this.backNavigation.hasLocalHandler() ||
+ !this.backNavigation.isRoot(this.currentPath()),
);
private readonly sidebarCollapsedStorageKey = 'inse.sidebar.collapsed';