Search...
redirect( )
Returns a response with a status code of 301 (Moved Permanently) or 302 (Found) and instructs the router to redirect to the given URL.
Description
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"
.
Syntax
function redirect(url: string, [statusCode: string]): Promise<WixRouterResponse>
redirect Parameters
NAME
TYPE
DESCRIPTION
url
string
The url to redirect to.
statusCode
Optional
string
The status code to use.
Related Content:
Was this helpful?
Create a redirect response
Copy Code
1import {redirect} from 'wix-router';23export function myRouter_Router(request) {45 return redirect("http://myothersite.com");6}
Create a redirect response with HTTP code 301
Copy Code
1import {redirect} from 'wix-router';23export function myRouter_Router(request) {45 return redirect("http://myothersite.com", "301");6}