usePageTitle.ts 828 B

1234567891011121314151617181920212223242526272829
  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. '/hosts': 'menu.hosts',
  11. '/settings': 'menu.settings',
  12. '/xray': 'menu.xray',
  13. '/outbound': 'menu.outbounds',
  14. '/routing': 'menu.routing',
  15. '/api-docs': 'menu.apiDocs',
  16. };
  17. export function usePageTitle() {
  18. const { pathname } = useLocation();
  19. const { t } = useTranslation();
  20. useEffect(() => {
  21. const key = TITLE_KEYS[pathname];
  22. const title = key ? t(key) : '3X-UI';
  23. const host = window.location.hostname;
  24. document.title = host ? `${host} - ${title}` : title;
  25. }, [pathname, t]);
  26. }