feat: refactor App component to integrate React Router for navigation
This commit is contained in:
parent
dd2f62593a
commit
98535aad7a
1 changed files with 66 additions and 70 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
|
import { BrowserRouter as Router, Routes, Route, Link } from "react-router-dom";
|
||||||
import { getSeed, getTrips, getTripItems, toggleTripItem } from "./api";
|
import { getSeed, getTrips, getTripItems, toggleTripItem } from "./api";
|
||||||
import ItemsPage from "./pages/ItemsPage";
|
import ItemsPage from "./pages/ItemsPage";
|
||||||
|
|
||||||
|
|
@ -24,23 +25,8 @@ export default function App() {
|
||||||
}
|
}
|
||||||
}, [view]);
|
}, [view]);
|
||||||
|
|
||||||
if (view === "items") {
|
|
||||||
return (
|
|
||||||
<div className="p-4 max-w-4xl mx-auto">
|
|
||||||
<div className="mb-4">
|
|
||||||
<button
|
|
||||||
onClick={() => setView("trips")}
|
|
||||||
className="bg-gray-500 text-white px-3 py-1 rounded"
|
|
||||||
>
|
|
||||||
← Zurück zu Trips
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<ItemsPage />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<Router>
|
||||||
<div className="p-4 max-w-2xl mx-auto">
|
<div className="p-4 max-w-2xl mx-auto">
|
||||||
<h1 className="text-2xl font-bold mb-4">Packlist</h1>
|
<h1 className="text-2xl font-bold mb-4">Packlist</h1>
|
||||||
|
|
||||||
|
|
@ -54,14 +40,18 @@ export default function App() {
|
||||||
>
|
>
|
||||||
Seed-Daten erzeugen
|
Seed-Daten erzeugen
|
||||||
</button>
|
</button>
|
||||||
<button
|
<Link to="/items">
|
||||||
className="bg-green-500 text-white px-4 py-2 rounded"
|
<button className="bg-green-500 text-white px-4 py-2 rounded">
|
||||||
onClick={() => setView("items")}
|
|
||||||
>
|
|
||||||
Alle Items
|
Alle Items
|
||||||
</button>
|
</button>
|
||||||
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Routes>
|
||||||
|
<Route
|
||||||
|
path="/"
|
||||||
|
element={
|
||||||
|
<>
|
||||||
{trips.map((trip) => (
|
{trips.map((trip) => (
|
||||||
<div key={trip.id} className="border rounded p-2 mb-4">
|
<div key={trip.id} className="border rounded p-2 mb-4">
|
||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center">
|
||||||
|
|
@ -97,6 +87,12 @@ export default function App() {
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route path="/items" element={<ItemsPage />} />
|
||||||
|
</Routes>
|
||||||
</div>
|
</div>
|
||||||
|
</Router>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue