Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/components/BackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,21 @@ const BackButton: React.FC<BackButtonProps> = ({
const location = useLocation();
const state =
(location.state as { backLabel?: string; backTo?: string }) || {};
const canGoBack = typeof window !== 'undefined' && window.history.length > 1;
// `history.length > 1` alone isn't a reliable signal that the previous
// entry is an in-app page — opening a deep link in a fresh tab counts
// the browser's own previous entry, so `navigate(-1)` would leave the
// app. Also require the referrer to be same-origin before stepping back.
const canGoBack = (() => {
if (typeof window === 'undefined') return false;
if (window.history.length <= 1) return false;
const ref = document.referrer;
if (!ref) return false;
try {
return new URL(ref).origin === window.location.origin;
} catch {
return false;
}
})();
const displayLabel = state.backLabel ?? label;

const handleClick = () => {
Expand Down