redirect: redirect (loader/action helper)

View source: R/helpers.R

redirectR Documentation

redirect (loader/action helper)

Description

https://reactrouter.com/api/utils/redirect

Usage

redirect(to)

Arguments

to

Character. Destination path.

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.

Value

A JS expression suitable for the loader argument of Route.

Examples

## Not run: 
Route(path = "/old", loader = redirect("/new"), element = NULL)

## End(Not run)


reactRouter documentation built on May 10, 2026, 5:07 p.m.