Search.../

ok( )

Returns a response with a status code 200 (OK) and instructs the router to show the selected page.

Description

The ok() function is used in the router() and afterRouter() hooks to continue the routing process to the specified page with a successful HTTP response code. The specified page must be a page found under the given router in the Velo Sidebar. For example, if you want to route to myRouter-page from the myRouter_Router() function, myRouter-page must be in the MyRouter Pages (Router) section of your site's Velo Sidebar.

Optionally, you can pass a data object to be used by the page routed to and header options for the page. The page routed to accesses the data passed to it using the getRouterData() function of wix-window-frontend with optional data and HTML header.

Syntax

function ok(Page: string | Array<string>, [routerReturnedData: Object], [head: HeadOptions]): Promise<WixRouterResponse>

ok Parameters

NAME
TYPE
DESCRIPTION
Page
string | Array<string>

A router page or an array of page fallbacks.

routerReturnedData
Optional
Object

A data object.

head
Optional
HeadOptions

HTML head members of the response.

Returns

Fulfilled - The router response object.

Return Type:

Related Content:

Was this helpful?

Create an okay response

Copy Code
1import {ok} from 'wix-router';
2
3export function myRouter_Router(request) {
4
5 return ok("router-page");
6}
Create an okay response with data and head options

Copy Code
1import {ok} from 'wix-router';
2
3export function myRouter_Router(request) {
4
5 return ok("router-page", dataObj, headOpts);
6}
Create an okay response with data and head options

Copy Code
1import { ok } from 'wix-router';
2
3export function myRouter_Router(request) {
4
5 let dataObj = {
6 "field1": "value1",
7 "field2": "value2"
8 };
9
10 let headOptions = {
11 "title": "A page title",
12 "metaTags": [
13 {
14 "name": "description",
15 "content": "A page description"
16 }, {
17 "name": "keywords",
18 "content": "Velo Example"
19 }, {
20 "name": "robots",
21 "content": "noindex"
22 }, {
23 "name": "og:title",
24 "content": "The Title"
25 }, {
26 "property": "og:image",
27 "content": "wix:image://v1/6...2.jpg/a.jpg#originWidth=970&originHeight=120"
28 }
29 ],
30 "links": [
31 {
32 "rel": "canonical",
33 "href": "http://mysite.com/somePage.html"
34 }
35 ],
36 "structuredData": [
37 {
38 "@context": "http://schema.org",
39 "@type": "Organization",
40 "name": "My Organization Name",
41 "url": "https://www.myorgdomain.com"
42 }, {
43 "@context": "http://schema.org",
44 "@type": "Person",
45 "email": "mailto:john.doe@somedomain.com",
46 "jobTitle": "Professor",
47 "name": "John Doe",
48 "telephone": "(555) 555-555"
49 }
50 ]
51 };
52
53 return ok("router-page", dataObj, headOptions);
54}