updated tab titles.

This commit is contained in:
2025-10-04 10:59:35 -04:00
parent 54cc4ea697
commit 097583ca0a
2 changed files with 28 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import React, { useEffect } from 'react';
import { BrowserRouter as Router, Route, Routes, useLocation } from 'react-router-dom';
import { ThemeProvider } from './contexts/ThemeContext';
import { UserProvider } from './contexts/UserContext';
import { CssBaseline } from '@mui/material';
@@ -16,6 +16,7 @@ function App() {
<ThemeProvider>
<CssBaseline />
<Router>
<TitleSetter />
<NavBar />
<Routes>
<Route path="/" element={<Login />} />
@@ -30,4 +31,25 @@ function App() {
);
}
export default App;
export default App;
// small helper component to set the browser tab title based on current route
function TitleSetter() {
const location = useLocation();
useEffect(() => {
// derive a friendly page name from the path
const path = location.pathname || '/';
let page = 'App';
if (path === '/' || path === '/login') page = 'Login';
else if (path.startsWith('/dashboard')) page = 'Dashboard';
else if (path.startsWith('/server/') && path.endsWith('/help')) page = 'Server Help';
else if (path.startsWith('/server/')) page = 'Server Settings';
else if (path.startsWith('/discord')) page = 'Discord';
else page = path.replace('/', '').split('/').map(p => p.charAt(0).toUpperCase() + p.slice(1)).join(' - ');
document.title = `ECS - ${page}`;
}, [location]);
return null;
}