One Logo Pool Ball
wwwwwwwwwwwwwwwwwww

<Redirect />

Redirect to another route. Useful for protecting routes or redirecting from old paths.

Usage

import { Redirect } from 'one'
export default function ProtectedPage() {
const { user } = useAuth()
if (!user) {
return <Redirect href="/login" />
}
return <Dashboard user={user} />
}

Props

PropTypeDescription
hrefHrefThe typed path to redirect to

Behavior

<Redirect> navigates with router.replace as soon as it mounts. It’s designed to be rendered conditionally from a layout guard, so it guards against the two ways that can otherwise turn into a redirect loop:

Because of this you don’t need a hand-rolled useEffect + useRef redirect in layout guards. Prefer the declarative <Redirect>.

Edit this page on GitHub.