Skip to contents

Usage

redirect(to)

Arguments

to

Character. Destination path.

Value

A JS expression suitable for the loader argument of Route.

Details

Returns a JS loader function that redirects to to. Pass as the loader argument of a Route to perform an unconditional redirect – typically used for guard routes that always send the user somewhere else.

Security: to must be a trusted, package-author-controlled string. javascript:, data:, and vbscript: URL schemes are rejected. If you build to from user-supplied input, validate it yourself before passing it in – never round-trip untrusted strings through redirect() into a navigation.

For conditional redirects inside a custom loader/action, call window.jsmodule['@/reactRouter'].helpers.redirect(to) from your own JS() string, e.g.


  loader = JS(
    "async () => {
       const { redirect } = window.jsmodule['@/reactRouter'].helpers;
       if (!authed()) return redirect('/login'); ...
     }"
  )

The data, replace, and redirectDocument helpers are exposed on the same namespace.

Examples

if (FALSE) { # \dontrun{
Route(path = "/old", loader = redirect("/new"), element = NULL)
} # }