Create and implement goBack helper function (#27015)

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
Aidan Timson
2025-09-12 10:39:45 +01:00
committed by GitHub
parent 7eb87c78cc
commit 0d8d18617c
17 changed files with 57 additions and 32 deletions

View File

@@ -63,3 +63,21 @@ export const navigate = async (
});
return true;
};
/**
* Navigate back in history, with fallback to a default path if no history exists.
* This prevents a user from getting stuck when they navigate directly to a page with no history.
*/
export const goBack = (fallbackPath?: string) => {
const { history } = mainWindow;
// Check if we have history to go back to
if (history.length > 1) {
history.back();
return;
}
// No history available, navigate to fallback path
const fallback = fallbackPath || "/";
navigate(fallback, { replace: true });
};