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".

Authorization

Request

This endpoint does not take any parameters

Response Object

Fulfilled - The redirect response object.

Returns an empty object.

Status/Error Codes

Was this helpful?

Create a redirect response

Copy Code
1import {redirect} from 'wix-router';
2
3export function myRouter_Router(request) {
4
5 return redirect("http://myothersite.com");
6}
Create a redirect response with HTTP code 301

Copy Code
1import {redirect} from 'wix-router';
2
3export function myRouter_Router(request) {
4
5 return redirect("http://myothersite.com", "301");
6}