scrimba
Learn React Router
Actions
redirectTo in VanLife
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

redirectTo in VanLife
AboutCommentsNotes
redirectTo in VanLife
Expand for more info
utils.js
run
preview
console
import { redirect } from "react-router-dom"

/**
* Challenge: Implement the `redirectTo` feature we just
* learned about to VanLife!
*
* 1. Pass the request to all calls to `requireAuth` (this
* includes all inline loaders on /host routes as well
* as the loaders defined separately inside the component
* files of /host routes)
* 2. Receive the request in requireAuth and pass along a
* search param of `redirectTo`
* 3. You're on your own for the last part :) You can do it! 💪
*/

export async function requireAuth() {
const isLoggedIn = localStorage.getItem("loggedin")

if (!isLoggedIn) {
throw redirect("/login?message=You must log in first.")
}
}
Console
/login?message=You%20must%20log%20in%20first.
-4:43