import React, { useEffect } from 'react'; import { BrowserRouter as Router, Route, Routes, Navigate, useLocation} from 'react-router-dom'; import Login from './components/Login'; import Register from './components/Register'; import Chat from './components/Chat'; import Opportunities from './components/Opportunities'; import { AuthProvider, useAuth } from './services/AuthContext'; const PrivateRoute = ({ children }) => { const { token, loading } = useAuth(); const location = useLocation(); if (loading) { // Show loading spinner or placeholder return
Loading...
; } return token ? children : ; }; const PublicRoute = ({ children }) => { const { token, loading } = useAuth(); const location = useLocation(); if (loading) { return
Loading...
; } return !token ? children : ; }; function AppRoutes() { const location = useLocation(); useEffect(() => { // Log the current route for debugging console.log('Current route:', location.pathname); }, [location]); return ( <> } /> } /> } /> {/* Catch all route */} } /> ); } function App() { return ( ); } export default App;