Prevent full-page reloads when clicking some currently selected navbar links (#33500)

## For #31752



https://github.com/user-attachments/assets/3eaff439-b2be-4849-a1ae-b21fe8d67b97


- [x] Changes file added for user-visible changes in `changes/`
- [x] QA'd all new/changed functionality manually

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
This commit is contained in:
jacobshandling 2025-09-26 08:51:04 -07:00 committed by GitHub
parent 82b9bc6b3e
commit f9e53aa9a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 11 deletions

View file

@ -0,0 +1 @@
- Fix a bug where clicking the currently selected navbar item would cause a full-page rerender

View file

@ -164,18 +164,15 @@ const SiteTopNav = ({
}
if (active && !isActiveDetailPage) {
const path = navItem.alwaysToPathname
let path = navItem.alwaysToPathname
? navItem.location.pathname
: currentPath;
const includeTeamId = (activePath: string) => {
if (currentQueryParams.team_id !== API_ALL_TEAMS_ID) {
return getPathWithQueryParams(path, {
team_id: currentQueryParams.team_id,
});
}
return activePath;
};
if (currentQueryParams.team_id !== API_ALL_TEAMS_ID) {
path = getPathWithQueryParams(path, {
team_id: currentQueryParams.team_id,
});
}
// Clicking an active link returns user to default page
// Resetting all filters except team ID
@ -183,14 +180,14 @@ const SiteTopNav = ({
// replace to the same url, which triggers a re-render)
return (
<li className={navItemClasses} key={`nav-item-${name}`}>
<a className={`${navItemBaseClass}__link`} href={includeTeamId(path)}>
<Link to={path} className={`${navItemBaseClass}__link`}>
<span
className={`${navItemBaseClass}__name`}
data-text={navItem.name}
>
{name}
</span>
</a>
</Link>
</li>
);
}