Changeset 8ca35dc for my-react-app/src/App.js
- Timestamp:
- 01/19/25 23:18:37 (4 months ago)
- Branches:
- main
- Children:
- f5b256e
- Parents:
- db39d9e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
my-react-app/src/App.js
rdb39d9e r8ca35dc 1 import {BrowserRouter as Router, Route, Routes, useNavigate} from 'react-router-dom';1 import {BrowserRouter as Router, Navigate, Route, Routes, useNavigate} from 'react-router-dom'; 2 2 import Customers from './components/Customers'; 3 3 import Layout from "./components/Layout"; … … 14 14 import { CuisineContext } from './components/CuisineContext'; 15 15 import RestaurantInfo from "./components/RestaurantInfo"; 16 import LoginForm from "./components/Login";16 import AuthForm from "./components/AuthForm"; 17 17 import AppContent from "./components/AppContent"; 18 import ReservationHistory from "./components/ReservationHistory"; 19 20 const ProtectedRoute = ({ element, isAuthenticated }) => { 21 return isAuthenticated ? element : <Navigate to="/login" />; 22 }; 18 23 19 24 const App = () => { 25 const [isAuthenticated, setIsAuthenticated] = React.useState(false); 26 27 React.useEffect(() => { 28 const token = localStorage.getItem('token'); 29 if (token) { 30 setIsAuthenticated(true); 31 } 32 }, []); 33 20 34 return ( 21 35 <Router> … … 23 37 <Routes> 24 38 <Route path="/" element={<Home />} /> 25 <Route path="/customers" element={<Customers />} /> 26 <Route path="/customers/add" element={<CustomerFormContainer/>} /> 27 <Route path="/customers/:id" element={<CustomerDetails />} /> 28 <Route path="/customers/edit/:id" element={<CustomerFormContainer/>} /> 29 <Route path="/restaurants" element={<Restaurants />} /> 30 <Route path="/restaurants/:id" element={<RestaurantDetails />} /> 31 <Route path="/reservations" element={<Reservations />} /> 32 <Route path="/reservationConfirmation/:tableNumber/:timeSlot/:restaurantId" element={<ReservationConfirmation />} /> 33 <Route path="/reservations/reservationEdit/:reservationId" element={<ReservationEdit />} /> 34 <Route path="/login" element={<LoginForm/>}/> 35 <Route path="/error" element={<ErrorPage/>}/> 39 <Route path="/customers" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<Customers />} />} /> 40 <Route path="/customers/add" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<CustomerFormContainer />} />} /> 41 <Route path="/customers/:id" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<CustomerDetails />} />} /> 42 <Route path="/customers/edit/:id" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<CustomerFormContainer />} />} /> 43 <Route path="/restaurants" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<Restaurants />} />} /> 44 <Route path="/restaurants/:id" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<RestaurantDetails />} />} /> 45 <Route path="/reservations" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<Reservations />} />} /> 46 <Route path="/reservationConfirmation/:tableNumber/:timeSlot/:restaurantId" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<ReservationConfirmation />} />} /> 47 <Route path="/reservations/reservationEdit/:reservationId" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<ReservationEdit />} />} /> 48 <Route path="/reservations-past" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<ReservationHistory />} />} /> 49 <Route path="/login" element={<AuthForm setIsAuthenticated={setIsAuthenticated} />} /> 50 51 <Route path="/error" element={<ErrorPage />} /> 36 52 </Routes> 37 <AppContent/>38 53 </Layout> 39 54 </Router> 40 55 ); 41 } 56 }; 42 57 43 58 … … 149 164 150 165 try { 151 const response = await axios.post('http://localhost:808 0/api/search', data);166 const response = await axios.post('http://localhost:8081/api/search', data); 152 167 const filteredRestaurants = response.data; 153 168 setFilteredRestaurants(filteredRestaurants); … … 163 178 const cuisineName = cuisine.replace('Searching by cuisine: ', ''); 164 179 try { 165 const response = await axios.post(`http://localhost:808 0/api/search/shortcut/${cuisineName}`, cuisineName);180 const response = await axios.post(`http://localhost:8081/api/search/shortcut/${cuisineName}`, cuisineName); 166 181 console.log(response.data); 167 182 setFilteredRestaurants(response.data)
Note:
See TracChangeset
for help on using the changeset viewer.