From 7660fa39218a7725b0839e9741c128aa6792c004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Fern=C3=A1ndez?= Date: Fri, 10 Jan 2025 14:59:06 +0100 Subject: [PATCH] Unified History: Going to a dashboard page creates two history entries (#98333) --- .../components/AppChrome/AppChromeService.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/public/app/core/components/AppChrome/AppChromeService.tsx b/public/app/core/components/AppChrome/AppChromeService.tsx index 55ec8cf7490..85f2a5cdd83 100644 --- a/public/app/core/components/AppChrome/AppChromeService.tsx +++ b/public/app/core/components/AppChrome/AppChromeService.tsx @@ -145,13 +145,17 @@ export class AppChromeService { return entries; } - let lastEntry = entries[0]; - if (!lastEntry || lastEntry.name !== newPageNav.text) { - lastEntry = { name: newPageNav.text, views: [], breadcrumbs, time: Date.now(), url: window.location.href }; - } - if (lastEntry !== entries[0]) { - entries = [lastEntry, ...entries]; + const lastEntry = entries[0]; + const newEntry = { name: newPageNav.text, views: [], breadcrumbs, time: Date.now(), url: window.location.href }; + const isSameUrl = lastEntry && newEntry.url === lastEntry.url; + + // To avoid adding an entry with the same url twice, we always use the latest one + if (isSameUrl) { + entries[0] = newEntry; + } else { + entries = [newEntry, ...entries]; } + return entries; } private ignoreStateUpdate(newState: AppChromeState, current: AppChromeState) {