Skip to content
Open
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
12 changes: 11 additions & 1 deletion src/components/BackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ const BackButton: React.FC<BackButtonProps> = ({
const navigate = useNavigate();
const location = useLocation();
const state = (location.state as { backTo?: string }) || {};
const canGoBack = typeof window !== 'undefined' && window.history.length > 1;
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 handleClick = () => {
if (canGoBack) {
Expand Down
Loading