Created
August 29, 2022 23:33
-
-
Save rushil1999/0d6bcacec52b85f291da45506f0fbaee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BrowserRouter, Routes, Route} from 'react-router-dom'; | |
import AuthContext from './contexts/AuthContextProvider.js' | |
import PrivatePath from './components/PrivatePath.js'; | |
import Login from './components/Login.js'; | |
import Navigation from './components/Navigation.js'; | |
import PrivateComponent from './components/PrivateComponent.js'; | |
import PublicComponent from './components/PublicComponent.js'; | |
import LandingPage from './components/LandingPage.js'; | |
function App() { | |
return ( | |
<div className="App"> | |
{/* The AuthContext component. All the components inside of this HTML Tag will have access to context */} | |
<AuthContext> | |
<BrowserRouter> | |
<Routes> | |
{/* This is a private component, that will look into the context, if the user is not logged in, redirect to Login Page*/ } | |
<Route path="/private-path" element={ | |
<PrivatePath> | |
<PrivateComponent/> | |
</PrivatePath> | |
}></Route> | |
{/* These are public components that do not require user to be logged in to visit these pages */} | |
<Route path="/public-path" element={<PublicComponent/>}></Route> | |
<Route path="/login" element={<Login/>}></Route> | |
<Route path="/navigation" element={<Navigation/>}></Route> | |
<Route path="" element={<LandingPage/>}></Route> | |
</Routes> | |
</BrowserRouter> | |
</AuthContext> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment