Files
clinicpro/assets/admin/hooks/useGoBack.ts
T
hamed 6876135a53 feat: add BlogBodySanitizer for HTML sanitization on article save
- Implemented BlogBodySanitizer to clean HTML content before saving articles, ensuring security against XSS attacks.
- Added tests for BlogBodySanitizer to verify that unsafe tags and attributes are stripped from the content.
- Introduced ApiLeastPrivilegeTest to ensure that unauthorized users cannot access sensitive API routes, maintaining strict access control.
2026-08-07 21:13:38 +03:30

25 lines
1.2 KiB
TypeScript

import { useCallback } from 'react';
import { useLocation, useNavigate } from 'react-router';
/**
* رفتار یکسانِ «بازگشت» در کل پنل: اگر کاربر از صفحهٔ دیگری داخل خود پنل آمده باشد،
* یک قدم در تاریخچه برمی‌گردد؛ اگر صفحه مستقیم باز شده باشد (لینک مستقیم، رفرش،
* بوکمارک) تاریخچه‌ای برای برگشتن نیست و به صفحهٔ والدِ همان بخش می‌رود.
*
* تشخیص «ورود مستقیم» با `location.key === 'default'` انجام می‌شود — همان چیزی که
* React Router برای اولین ورودیِ تاریخچه می‌گذارد؛ `history.length` قابل اتکا نیست
* چون تب‌های قبلی مرورگر هم در آن شمرده می‌شوند.
*/
export function useGoBack(fallback: string): () => void {
const navigate = useNavigate();
const location = useLocation();
return useCallback(() => {
if (location.key !== 'default') {
navigate(-1);
return;
}
navigate(fallback, { replace: true });
}, [navigate, location.key, fallback]);
}