| redirect | R Documentation |
https://reactrouter.com/api/utils/redirect
redirect(to)
to |
Character. Destination path. |
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.
A JS expression suitable for the loader
argument of Route.
## Not run:
Route(path = "/old", loader = redirect("/new"), element = NULL)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.