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.
LinkAn object representing a link tag.
MetaTagAn object representing a meta tag.

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.

Description

The information you set using the head property, such as links or meta tags, overwrites any head information set earlier.

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",
  *   "metaTags": [
  *     {
  *       "name": "description",
  *       "content": "A page description"
  *     }, {
  *       "name": "keywords",
  *       "content": "Corvid Example"
  *     }, {
  *       "name": "robots",
  *       "content": "noindex"
  *     }, {
  *       "name": "og:title",
  *       "content": "The Title"
  *     }, {
  *       "property": "og:image",
  *       "content": "wix:image://v1/6...2.jpg/a.jpg#originWidth=970&originHeight=120"
  *     }
  *   ],
  *   "links": [
  *     {
  *       "rel": "canonical",
  *       "href": "http://mysite.com/somePage.html"
  *     }
  *   ],
  *   "structuredData": [
  *     {
  *       "@context": "http://schema.org",
  *       "@type": "Organization",
  *       "name": "My Organization Name",
  *       "url": "https://www.myorgdomain.com"
  *     }, {
  *       "@context": "http://schema.org",
  *       "@type": "Person",
  *       "email": "mailto:john.doe@somedomain.com",
  *       "jobTitle": "Professor",
  *       "name": "John Doe",
  *       "telephone": "(555) 555-555"
  *     }
  *   ]
  * }
 */

Set the response's head options

export function myRouter_Router(request) {

  let headOptions = {
    "title": "A page title",
    "metaTags": [
      {
        "name": "description",
        "content": "A page description"
      }, {
        "name": "keywords",
        "content": "Corvid Example"
      }, {
        "name": "robots",
        "content": "noindex"
      }, {
        "name": "og:title",
        "content": "The Title"
      }, {
        "property": "og:image",
        "content": "wix:image://v1/6...2.jpg/a.jpg#originWidth=970&originHeight=120"
      }
    ],
    "links": [
      {
        "rel": "canonical",
        "href": "http://mysite.com/somePage.html"
      }
    ],
    "structuredData": [
      {
        "@context": "http://schema.org",
        "@type": "Organization",
        "name": "My Organization Name",
        "url": "https://www.myorgdomain.com"
      }, {
        "@context": "http://schema.org",
        "@type": "Person",
        "email": "mailto:john.doe@somedomain.com",
        "jobTitle": "Professor",
        "name": "John Doe",
        "telephone": "(555) 555-555"
      }
    ]
  };

  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: Array<MetaTag>
  links: Array<Link>
  structuredData: Array<Object>
}
MEMBERS
?
The properties of an object.
title
string
The page title. Written to the <title> tag.
description
string

Deprecated: Use the new metaTags format instead.

The page description.

keywords
string

Deprecated: Use the new metaTags format instead.

The page keywords.

noIndex
boolean

Deprecated: Use the new metaTags format instead.

Indicates whether to add a meta tag that prevents search engines from indexing the page.

metaTags
Array<MetaTag>

The page's SEO-related meta tags.

When setting og:image meta tags, the content can be and external image URL or a Media Manager image URL as described here.

Deprecated format: An object with key:value pairs where the key is the meta tag name and the value is the content.

links
Array<Link>

The page's SEO-related link tags which provide additional SEO information about the page. For example, you can set a link to a canonical or alternate version of the page.

structuredData
Array<Object>

The page's structured data, which helps search engines understand more about the page and your business so they can display a richer snippet of the page in search results.

Examples

HeadOptions in page head

// Given the following HeadOptions
{
  "title": "A page title",
  "metaTags": [
    {
      "name": "description",
      "content": "A page description"
    }, {
      "name": "keywords",
      "content": "Corvid Example"
    }, {
      "name": "robots",
      "content": "noindex"
    }, {
      "name": "og:title",
      "content": "The Title"
    }, {
      "property": "og:image",
      "content": "http://somesite/someimage.jpg"
    }
  ],
  "links": [
    {
      "rel": "canonical",
      "href": "http://mysite.com/somePage.html"
    }
  ],
  "structuredData": [
    {
      "@context": "http://schema.org",
      "@type": "Organization",
      "name": "My Organization Name",
      "url": "https://www.myorgdomain.com"
    }, {
      "@context": "http://schema.org",
      "@type": "Person",
      "email": "mailto:john.doe@somedomain.com",
      "jobTitle": "Professor",
      "name": "John Doe",
      "telephone": "(555) 555-555"
    }
  ]
}

// The HTML page head will contain
<head>
  <title>A page title</title>
  <meta name="description" content="A page description"/>
  <meta name="keywords" content="Corvid Example"/>
  <meta name="robots" content="noindex"/>
  <meta name="og:title" content="The Title"/>
  <meta name="og:image" content="http://somesite/someimage.jpg"/>
  <link rel="canonical" href="http://mysite.com/somePage.html"/>
  <script type="application/ld+json">
  {
    "@context": "http://schema.org",
    "@type": "Organization",
    "name": "My Organization Name",
    "url": "https://www.myorgdomain.com"
  }, {
    "@context": "http://schema.org",
    "@type": "Person",
    "email": "mailto:john.doe@somedomain.com",
    "jobTitle": "Professor",
    "name": "John Doe",
    "telephone": "(555) 555-555"
  }
  </script>
</head>

Get the head options of the response

export function myRouter_Router(request) {

  let head = response.head;

 /*
  * {
  *   "title": "A page title",
  *   "metaTags": [
  *     {
  *       "name": "description",
  *       "content": "A page description"
  *     }, {
  *       "name": "keywords",
  *       "content": "Corvid Example"
  *     }, {
  *       "name": "robots",
  *       "content": "noindex"
  *     }, {
  *       "name": "og:title",
  *       "content": "The Title"
  *     }, {
  *       "property": "og:image",
  *       "content": "wix:image://v1/6...2.jpg/a.jpg#originWidth=970&originHeight=120"
  *     }
  *   ],
  *   "links": [
  *     {
  *       "rel": "canonical",
  *       "href": "http://mysite.com/somePage.html"
  *     }
  *   ],
  *   "structuredData": [
  *     {
  *       "@context": "http://schema.org",
  *       "@type": "Organization",
  *       "name": "My Organization Name",
  *       "url": "https://www.myorgdomain.com"
  *     }, {
  *       "@context": "http://schema.org",
  *       "@type": "Person",
  *       "email": "mailto:john.doe@somedomain.com",
  *       "jobTitle": "Professor",
  *       "name": "John Doe",
  *       "telephone": "(555) 555-555"
  *     }
  *   ]
  * }
 */

Set the page options of the response

export function myRouter_Router(request) {

  let headOptions = {
    "title": "A page title",
    "metaTags": [
      {
        "name": "description",
        "content": "A page description"
      }, {
        "name": "keywords",
        "content": "Corvid Example"
      }, {
        "name": "robots",
        "content": "noindex"
      }, {
        "name": "og:title",
        "content": "The Title"
      }, {
        "property": "og:image",
        "content": "wix:image://v1/6...2.jpg/a.jpg#originWidth=970&originHeight=120"
      }
    ],
    "links": [
      {
        "rel": "canonical",
        "href": "http://mysite.com/somePage.html"
      }
    ],
    "structuredData": [
      {
        "@context": "http://schema.org",
        "@type": "Organization",
        "name": "My Organization Name",
        "url": "https://www.myorgdomain.com"
      }, {
        "@context": "http://schema.org",
        "@type": "Person",
        "email": "mailto:john.doe@somedomain.com",
        "jobTitle": "Professor",
        "name": "John Doe",
        "telephone": "(555) 555-555"
      }
    ]
  };

  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",
    "metaTags": [
      {
        "name": "description",
        "content": "A page description"
      }, {
        "name": "keywords",
        "content": "Corvid Example"
      }, {
        "name": "robots",
        "content": "noindex"
      }, {
        "name": "og:title",
        "content": "The Title"
      }, {
        "property": "og:image",
        "content": "wix:image://v1/6...2.jpg/a.jpg#originWidth=970&originHeight=120"
      }
    ],
    "links": [
      {
        "rel": "canonical",
        "href": "http://mysite.com/somePage.html"
      }
    ],
    "structuredData": [
      {
        "@context": "http://schema.org",
        "@type": "Organization",
        "name": "My Organization Name",
        "url": "https://www.myorgdomain.com"
      }, {
        "@context": "http://schema.org",
        "@type": "Person",
        "email": "mailto:john.doe@somedomain.com",
        "jobTitle": "Professor",
        "name": "John Doe",
        "telephone": "(555) 555-555"
      }
    ]
  };

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

Link

An object representing a link tag.

Syntax

type Link = {
  rel: string
  href: string
}
MEMBERS
?
rel(Optional)
string
The relationship of the linked resource to the current page.
href(Optional)
string
The URL of the linked resource.

Examples

Get the head options of the response

export function myRouter_Router(request) {

  let head = response.head;

 /*
  * {
  *   "title": "A page title",
  *   "metaTags": [
  *     {
  *       "name": "description",
  *       "content": "A page description"
  *     }, {
  *       "name": "keywords",
  *       "content": "Corvid Example"
  *     }, {
  *       "name": "robots",
  *       "content": "noindex"
  *     }, {
  *       "name": "og:title",
  *       "content": "The Title"
  *     }, {
  *       "property": "og:image",
  *       "content": "wix:image://v1/6...2.jpg/a.jpg#originWidth=970&originHeight=120"
  *     }
  *   ],
  *   "links": [
  *     {
  *       "rel": "canonical",
  *       "href": "http://mysite.com/somePage.html"
  *     }
  *   ],
  *   "structuredData": [
  *     {
  *       "@context": "http://schema.org",
  *       "@type": "Organization",
  *       "name": "My Organization Name",
  *       "url": "https://www.myorgdomain.com"
  *     }, {
  *       "@context": "http://schema.org",
  *       "@type": "Person",
  *       "email": "mailto:john.doe@somedomain.com",
  *       "jobTitle": "Professor",
  *       "name": "John Doe",
  *       "telephone": "(555) 555-555"
  *     }
  *   ]
  * }
 */

Set the page options of the response

export function myRouter_Router(request) {

  let headOptions = {
    "title": "A page title",
    "metaTags": [
      {
        "name": "description",
        "content": "A page description"
      }, {
        "name": "keywords",
        "content": "Corvid Example"
      }, {
        "name": "robots",
        "content": "noindex"
      }, {
        "name": "og:title",
        "content": "The Title"
      }, {
        "property": "og:image",
        "content": "wix:image://v1/6...2.jpg/a.jpg#originWidth=970&originHeight=120"
      }
    ],
    "links": [
      {
        "rel": "canonical",
        "href": "http://mysite.com/somePage.html"
      }
    ],
    "structuredData": [
      {
        "@context": "http://schema.org",
        "@type": "Organization",
        "name": "My Organization Name",
        "url": "https://www.myorgdomain.com"
      }, {
        "@context": "http://schema.org",
        "@type": "Person",
        "email": "mailto:john.doe@somedomain.com",
        "jobTitle": "Professor",
        "name": "John Doe",
        "telephone": "(555) 555-555"
      }
    ]
  };

  let response.head = headOptions;

MetaTag

An object representing a meta tag.

Description

The keys in the object represent the keys in the tag and the values in the object represent the values in the tag.

For example:

 {
   "property": "og:image",
   "content": "https://.../Wix+logo.jpg"
 }

Produces:

 <meta property="og:image" content="https://.../Wix+logo.jpg"/>

Syntax

type MetaTag = {
  name: string
  property: string
  http-equiv: string
  content: string
}
MEMBERS
?
The properties of an object.
name(Optional)
string
Name of the meta tag. Either name or property are required.
property(Optional)
string
Name of the meta tag property. Either property or name are required.
http-equiv(Optional)
string
HTTP header that corresponds to the content.
content
string

Meta tag value. For og:image meta tags, the content can be an external image URL or a Media Manager image URL as described here.

Examples

Get the head options of the response

export function myRouter_Router(request) {

  let head = response.head;

 /*
  * {
  *   "title": "A page title",
  *   "metaTags": [
  *     {
  *       "name": "description",
  *       "content": "A page description"
  *     }, {
  *       "name": "keywords",
  *       "content": "Corvid Example"
  *     }, {
  *       "name": "robots",
  *       "content": "noindex"
  *     }, {
  *       "name": "og:title",
  *       "content": "The Title"
  *     }, {
  *       "property": "og:image",
  *       "content": "wix:image://v1/6...2.jpg/a.jpg#originWidth=970&originHeight=120"
  *     }
  *   ],
  *   "links": [
  *     {
  *       "rel": "canonical",
  *       "href": "http://mysite.com/somePage.html"
  *     }
  *   ],
  *   "structuredData": [
  *     {
  *       "@context": "http://schema.org",
  *       "@type": "Organization",
  *       "name": "My Organization Name",
  *       "url": "https://www.myorgdomain.com"
  *     }, {
  *       "@context": "http://schema.org",
  *       "@type": "Person",
  *       "email": "mailto:john.doe@somedomain.com",
  *       "jobTitle": "Professor",
  *       "name": "John Doe",
  *       "telephone": "(555) 555-555"
  *     }
  *   ]
  * }
 */

Set the page options of the response

export function myRouter_Router(request) {

  let headOptions = {
    "title": "A page title",
    "metaTags": [
      {
        "name": "description",
        "content": "A page description"
      }, {
        "name": "keywords",
        "content": "Corvid Example"
      }, {
        "name": "robots",
        "content": "noindex"
      }, {
        "name": "og:title",
        "content": "The Title"
      }, {
        "property": "og:image",
        "content": "wix:image://v1/6...2.jpg/a.jpg#originWidth=970&originHeight=120"
      }
    ],
    "links": [
      {
        "rel": "canonical",
        "href": "http://mysite.com/somePage.html"
      }
    ],
    "structuredData": [
      {
        "@context": "http://schema.org",
        "@type": "Organization",
        "name": "My Organization Name",
        "url": "https://www.myorgdomain.com"
      }, {
        "@context": "http://schema.org",
        "@type": "Person",
        "email": "mailto:john.doe@somedomain.com",
        "jobTitle": "Professor",
        "name": "John Doe",
        "telephone": "(555) 555-555"
      }
    ]
  };

  let response.head = headOptions;