Add routing

This commit is contained in:
2025-02-17 21:23:38 +01:00
parent b6c7edecfd
commit 1cbcb8ce4c
11 changed files with 119 additions and 5 deletions
+13 -1
View File
@@ -1,7 +1,19 @@
import { Route, Routes } from 'react-router';
import Home from 'pages/Home';
import Languages from 'pages/Languages';
import Typing from 'pages/Typing';
import NotFound from 'pages/NotFound';
function App() {
return <Typing />;
return (
<Routes>
<Route index element={<Home />} />
<Route path='languages' element={<Languages />} />
<Route path='typing/:lang' element={<Typing />} />
<Route path='*' element={<NotFound />} />
</Routes>
);
}
export default App;
+6 -1
View File
@@ -1,8 +1,13 @@
import { createRoot } from 'react-dom/client';
import { BrowserRouter } from 'react-router';
import App from './App.tsx';
import './index.css';
// TODO: Bring back strict mode when building and deploying
createRoot(document.getElementById('root')).render(<App />);
createRoot(document.getElementById('root')).render(
<BrowserRouter>
<App />
</BrowserRouter>
);
+3
View File
@@ -0,0 +1,3 @@
.container {
text-align: left;
}
+11
View File
@@ -0,0 +1,11 @@
import './index.css';
function Home() {
return (
<div className='container'>
<h1>Home</h1>
</div>
);
}
export default Home;
+3
View File
@@ -0,0 +1,3 @@
.container {
text-align: left;
}
+11
View File
@@ -0,0 +1,11 @@
import './index.css';
function Languages() {
return (
<div className='container'>
<h1>Languages</h1>
</div>
);
}
export default Languages;
+3
View File
@@ -0,0 +1,3 @@
.container {
text-align: left;
}
+11
View File
@@ -0,0 +1,11 @@
import './index.css';
function NotFound() {
return (
<div className='container'>
<h1>Not Found</h1>
</div>
);
}
export default NotFound;
+3 -1
View File
@@ -6,8 +6,10 @@ import Code from 'components/Code';
import Stats from 'components/Stats';
import './index.css';
import { useParams } from 'react-router';
function Typing() {
const {lang} = useParams();
const [code, setCode] = useState<string>('');
const [loaded, setLoaded] = useState<boolean>(false);
@@ -16,7 +18,7 @@ function Typing() {
setCode('');
const response = await fetch(
`${import.meta.env.VITE_API_URL}/generate?lang=lisp`,
`${import.meta.env.VITE_API_URL}/generate?lang=${lang}`,
);
if (!response.ok || !response.body) return;