updated tab titles.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user