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
A router page or an array of page fallbacks.
A data object.
HTML head members of the response.
Related Content:
Was this helpful?
1import {ok} from 'wix-router';23export function myRouter_Router(request) {45 return ok("router-page");6}
1import {ok} from 'wix-router';23export function myRouter_Router(request) {45 return ok("router-page", dataObj, headOpts);6}
1import { ok } from 'wix-router';23export function myRouter_Router(request) {45 let dataObj = {6 "field1": "value1",7 "field2": "value2"8 };910 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 };5253 return ok("router-page", dataObj, headOptions);54}