Returns a response with a status code of 301 (Moved Permanently) or 302 (Found) and instructs the router to redirect to the given URL.
The redirect()
function is used in the router()
, beforeRouter()
,
and afterRouter()
hooks to redirect to a page that is
not the requested page.
Optionally, you can pass a status code of "301"
or "302"
using the statusCode
parameter. If any other status code is passed or no status code is passed at all,
the status code defaults to "302"
.
function redirect(url: string, statusCode: string): Promise<WixRouterResponse>;
The url to redirect to.
The status code to use.
import { redirect } from "wix-router";
export function myRouter_Router(request) {
return redirect("http://myothersite.com");
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.