% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/helpers.R
\name{redirect}
\alias{redirect}
\title{redirect (loader/action helper)}
\usage{
redirect(to)
}
\arguments{
\item{to}{Character. Destination path.}
}
\value{
A \code{\link{JS}} expression suitable for the \code{loader}
  argument of \code{\link{Route}}.
}
\description{
\url{https://reactrouter.com/api/utils/redirect}
}
\details{
Returns a \code{\link{JS}} loader function that redirects to \code{to}.
Pass as the \code{loader} argument of a \code{\link{Route}} to perform
an unconditional redirect -- typically used for guard routes that always
send the user somewhere else.

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

For conditional redirects inside a custom loader/action, call
\code{window.jsmodule['@/reactRouter'].helpers.redirect(to)} from your own
\code{JS()} string, e.g.
\preformatted{
  loader = JS(
    "async () => {
       const { redirect } = window.jsmodule['@/reactRouter'].helpers;
       if (!authed()) return redirect('/login'); ...
     }"
  )
}

The \code{data}, \code{replace}, and \code{redirectDocument} helpers are
exposed on the same namespace.
}
\examples{
\dontrun{
Route(path = "/old", loader = redirect("/new"), element = NULL)
}

}
