scrimba
Frontend Career Path
Advanced React
React Router
VanLife Protected Routes (FDCP)
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

VanLife Protected Routes (FDCP)
AboutCommentsNotes
VanLife Protected Routes (FDCP)
Expand for more info
index.jsx
run
preview
console
import React from 'react';
import ReactDOM from 'react-dom/client';
import { BrowserRouter, Routes, Route, Link } from "react-router-dom"
import Home from "./pages/Home"
import About from "./pages/About"
import Vans from "./pages/Vans/Vans"
import VanDetail from "./pages/Vans/VanDetail"
import Login from "./pages/Login"
import Dashboard from "./pages/Host/Dashboard"
import Income from "./pages/Host/Income"
import Reviews from "./pages/Host/Reviews"
import HostVans from "./pages/Host/HostVans"
import HostVanDetail from "./pages/Host/HostVanDetail"
import HostVanInfo from "./pages/Host/HostVanInfo"
import HostVanPricing from "./pages/Host/HostVanPricing"
import HostVanPhotos from "./pages/Host/HostVanPhotos"
import NotFound from "./pages/NotFound"
import Layout from "./components/Layout"
import HostLayout from "./components/HostLayout"

import "./server"

function App() {
/**
* Challenge: Create the AuthRequired Layout Route to protect
* all the /host routes.
*
* For now, just use `const auth = false`
* to determine the authenticated status of the user, and
* either send them to the /login route, or render the Outlet
*/

return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Layout />}>
<Route index element={<Home />} />
<Route path="about" element={<About />} />
<Route path="vans" element={<Vans />} />
<Route path="vans/:id" element={<VanDetail />} />
<Route
path="login"
element={<Login />}
/>

<Route path="host" element={<HostLayout />}>
<Route index element={<Dashboard />} />
<Route path="income" element={<Income />} />
<Route path="reviews" element={<Reviews />} />
<Route path="vans" element={<HostVans />} />
<Route path="vans/:id" element={<HostVanDetail />}>
<Route index element={<HostVanInfo />} />
<Route path="pricing" element={<HostVanPricing />} />
<Route path="photos" element={<HostVanPhotos />} />
</Route>
</Route>

<Route path="*" element={<NotFound />} />
</Route>
</Routes>
</BrowserRouter>
)
}

ReactDOM
.createRoot(document.getElementById('root'))
.render(<App />);
Console
/host
-3:25