[]previous and next page

redirect

Control flow: throw the result to redirect.

Control flow: throw the result to redirect. Identical from beforeLoad and from a loader. The target is a string, or an object with the same typed params, search and hash that links and navigation take.

Import#

ts
import { redirect } from "@shadow-js/router";

Signature#

ts
function redirect(to: string, options?: { readonly replace?: boolean }): RedirectSignal

function redirect<P extends string>(target: RedirectTarget<P>): RedirectSignal

Parameters#

Name Description
to Target: a path relative to the app, an absolute path, or { to, params?, search?, hash?, replace? }.
options replace defaults to true (the string form).

Returns#

The signal to throw.

Throws#

  • RangeError when a pattern's required param is missing.

Examples#

ts
throw redirect("/login")
ts
throw redirect({ to: "/posts/:id", params: { id: "7" }, search: { tab: "edit" } })