CorvidReference

WixRouterResponse

An object representing a response to a request received by a router.

Table of Contents

PROPERTIES

?
Store values associated with an object.
dataSets or gets the data to pass with the response.
headSets or gets the members to be written to the HTML head of the page.
messageSets or gets the response message to be used when responding with status codes 4xx and 5xx.
pageSets or gets the page to route to.
redirectUrlSets or gets the url to redirect to when responding with status codes 301 and 302.
statusSets or gets the response's HTTP status code.

OBJECTS

?
Objects used when setting, getting, or calling the properties and methods listed above.
HeadOptionsMembers of the HTML head.

data

Sets or gets the data to pass with the response.

Description

A data object to be used by the page routed to. The page routed to accesses the data passed to it using the getRouterData() function of wix-window. with optional data and HTML header.

Syntax

get data(): Object
set data(value: Object): void
TYPE
?
The kind of data the property stores.
Object

Examples

Get the data that is passed with the response

export function myRouter_Router(request) {

  let data = response.data;
  /*
  * {
  *   "title": "A",
  *   "imageSite": "http://static.wixstatic.com/media/",
  *   "image": "b8f383e0fe2b478ea91362b707ef267b.jpg"
  * }
  */

}

Set the data that is passed with the response

export function myRouter_Router(request) {

  response.data = {
    "title": "A",
    "imageSite": "http://static.wixstatic.com/media/",
    "image": "b8f383e0fe2b478ea91362b707ef267b.jpg"
  };

}

head

Sets or gets the members to be written to the HTML head of the page.

Syntax

get head(): HeadOptions
set head(value: HeadOptions): void

Examples

Get the response's head options

export function myRouter_Router(request) {

  let head = response.head;

  /*
  * {
  *   "title": "A page title",
  *   "description": "A page description",
  *   "keywords": "wix code example",
  *   "noIndex": true,
  *   "metaTags": {
  *     "copyright": "Wix.com",
  *     "Classification": "Example",
  *     "og:title": "The Rock",
  *     "og:image": "http://ia.media-imdb.com/rock.jpg"
  *   }
  * }
  */

}

Set the response's head options

export function myRouter_Router(request) {

  let headOptions = {
    "title": "A page title",
    "description": "A page description",
    "keywords": "wix code example",
    "noIndex": true,
    "metaTags": {
      "copyright": "Wix.com",
      "Classification": "Example",
      "og:title": "The Rock",
      "og:image": "http://ia.media-imdb.com/rock.jpg"
    }
  };

  let response.head = headOptions;

}

message

Sets or gets the response message to be used when responding with status codes 4xx and 5xx.

Syntax

get message(): string
set message(value: string): void
TYPE
?
The kind of data the property stores.
string

Examples

Get the response message

export function myRouter_Router(request) {

  let message = response.message; // "Not found"

}

Set the response message

export function myRouter_Router(request) {

  response.message = "Not found";

}

page

Sets or gets the page to route to.

Syntax

get page(): string
set page(value: string): void
TYPE
?
The kind of data the property stores.
string

Examples

Get the page the response routes to

export function myRouter_Router(request) {

  let page = response.page; // "myRouter-page"

}

Set the page the response routes to

export function myRouter_Router(request) {

  response.page = "myRouter-page";

}

redirectUrl

Sets or gets the url to redirect to when responding with status codes 301 and 302.

Syntax

get redirectUrl(): string
set redirectUrl(value: string): void
TYPE
?
The kind of data the property stores.
string

Examples

Get the URL to redirect to

export function myRouter_Router(request) {

  let redirectUrl = response.redirectUrl;
  // "http://someothersite.com"

}

Set the URL to redirect to

export function myRouter_Router(request) {

  response.redirectUrl = "http://someothersite.com";

}

status

Sets or gets the response's HTTP status code.

Syntax

get status(): number
set status(value: number): void
TYPE
?
The kind of data the property stores.
number

Examples

Get the response's HTTP status code

export function myRouter_Router(request) {

  let status = response.status; // 200

}

Set the response's HTTP status code

export function myRouter_Router(request) {

  response.status = 200;

}

HeadOptions

Members of the HTML head.

Description

The HeadOptions object defines the HTML head of the page to respond with. The members of the HeadOptions are written to the HTML head for use by browsers and SEO bots.

Syntax

type HeadOptions = {
  title: string
  description: string
  keywords: string
  noIndex: boolean
  metaTags: Object
}
MEMBERS
?
The properties of an object.
title
string
The page title. Written to the <title> tag.
description
string
The page description. Written to the <meta name="description" content="<value>"> tag.
keywords
string
The page keywords. Written to the <meta name="keywords" content="<value>"> tag.
noIndex
boolean
Indicates whether to add a meta tag that prevents search engines from indexing the page. Setting noIndex to true will add <meta name="robots" content="noindex">.
metaTags
Object
Other meta tags of the head. An object with key:value pairs where the key is the meta tag name and the value is the content.

Examples

HeadOptions in page head

// Given the following HeadOptions
{
  "title": "A page title",
  "description": "A page description",
  "keywords": "wix code example",
  "noIndex": true,
  "metaTags": {
    "copyright": "Wix.com",
    "Classification": "Example",
    "og:title": "The Rock",
    "og:image": "http://ia.media-imdb.com/rock.jpg"
  }
}

// The HTML page head will contain
<head>
  <title>A page title</title>
  <meta name="description" content="A page description"/>
  <meta name="keywords" content="wix code example"/>
  <meta name="robots" content="noindex"/>
  <meta name="copyright" content="Wix.com"/>
  <meta name="Classification" content="Example"/>
  <meta name="og:title" content="The Title"/>
  <meta name="og:image" content="http://somesite/someimage.jpg"/>
</head>

Get the head options of the response

export function myRouter_Router(request) {

  let head = response.head;

  /*
  * {
  *   "title": "A page title",
  *   "description": "A page description",
  *   "keywords": "wix code example",
  *   "noIndex": true,
  *   "metaTags": {
  *     "copyright": "Wix.com",
  *     "Classification": "Example",
  *     "og:title": "The Rock",
  *     "og:image": "http://ia.media-imdb.com/rock.jpg"
  *   }
  * }
  */

}

Set the page options of the response

export function myRouter_Router(request) {

  let headOptions = {
    "title": "A page title",
    "description": "A page description",
    "keywords": "wix code example",
    "noIndex": true,
    "metaTags": {
      "copyright": "Wix.com",
      "Classification": "Example",
      "og:title": "The Rock",
      "og:image": "http://ia.media-imdb.com/rock.jpg"
    }
  };

  let response.head = headOptions;

}

Create an okay response with data and head options

import {ok} from 'wix-router';

export function myRouter_Router(request) {

  let dataObj = {
    "field1": "value1",
    "field2": "value2"
  };

  let headOptions = {
    "title": "A page title",
    "description": "A page description",
    "keywords": "wix code example",
    "noIndex": true,
    "metaTags": {
      "copyright": "Wix.com",
      "Classification": "Example",
      "og:title": "The Rock",
      "og:image": "http://ia.media-imdb.com/rock.jpg"
    }
  };

  return ok("router-page", dataObj, headOptions);
}