Skip to content

Commit

Permalink
feat: Add dynamic page titles with route-based translations
Browse files Browse the repository at this point in the history
  • Loading branch information
harperreed committed Feb 18, 2025
1 parent 5c4cb71 commit 691bff4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/chat/app/+html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function Root({ children }: PropsWithChildren) {
return (
<html lang="en">
<head>
<title>Orbiting</title>
<meta charSet="utf-8" />
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta
Expand Down
28 changes: 27 additions & 1 deletion packages/chat/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Stack } from "expo-router";
import { Stack, usePathname } from "expo-router";
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import './i18n/config';
import { WelcomeModal } from './components/WelcomeModal';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
Expand All @@ -11,6 +12,31 @@ import { ErrorBoundary } from './components/ErrorBoundary';

function AppContent() {
const { currentTheme } = useSettings();
const { t } = useTranslation();
const pathname = usePathname();

useEffect(() => {
let title = 'Orbiting';

switch (pathname) {
case '/history':
title = `${t('history')} | Orbiting`;
break;
case '/settings':
title = `${t('settings')} | Orbiting`;
break;
case '/help':
title = `${t('help')} | Orbiting`;
break;
case '/about':
title = `${t('about')} | Orbiting`;
break;
}

if (typeof document !== 'undefined') {
document.title = title;
}
}, [pathname, t]);

return (
<PaperProvider theme={currentTheme}>
Expand Down

0 comments on commit 691bff4

Please sign in to comment.