usePageTitle.ts 739 B

1234567891011121314151617181920212223242526
  1. import { useEffect } from 'react';
  2. import { useLocation } from 'react-router-dom';
  3. import { useTranslation } from 'react-i18next';
  4. const TITLE_KEYS: Record<string, string> = {
  5. '/': 'menu.dashboard',
  6. '/inbounds': 'menu.inbounds',
  7. '/clients': 'menu.clients',
  8. '/groups': 'menu.groups',
  9. '/nodes': 'menu.nodes',
  10. '/settings': 'menu.settings',
  11. '/xray': 'menu.xray',
  12. '/api-docs': 'menu.apiDocs',
  13. };
  14. export function usePageTitle() {
  15. const { pathname } = useLocation();
  16. const { t } = useTranslation();
  17. useEffect(() => {
  18. const key = TITLE_KEYS[pathname];
  19. const title = key ? t(key) : '3X-UI';
  20. const host = window.location.hostname;
  21. document.title = host ? `${host} - ${title}` : title;
  22. }, [pathname, t]);
  23. }