|
1 | 1 | { "name": "wix-router",
|
2 | 2 | "mixes": [],
|
3 |
| - "labels": |
4 |
| - [ "changed" ], |
| 3 | + "labels": [], |
5 | 4 | "location":
|
6 | 5 | { "lineno": 1,
|
7 | 6 | "filename": "router.js" },
|
8 | 7 | "docs":
|
9 | 8 | { "summary": "This module contains the APIs for code routers and data binding router hooks.",
|
10 | 9 | "description":
|
11 |
| - [ "The code for both routers and data binding router hooks is defined in the", |
12 |
| - " **routers.js** file that you [set up](https://support.wix.com/en/article/velo-creating-a-router#add-a-router) in the Code Files' Backend section of the [Velo Sidebar](https://support.wix.com/en/article/velo-working-with-the-velo-sidebar).", |
| 10 | + [ "The Wix Router API allows you to handle certain incoming requests to your site's pages and sitemap and customize the responses.", |
13 | 11 | "",
|
14 |
| - " > **Note:** You do not create the **routers.js** file manually. When you [set it up](https://support.wix.com/en/article/velo-creating-a-router#add-a-router), it will be", |
15 |
| - " created for you.", |
| 12 | + "Some things you might do with the Router API are:", |
| 13 | + " * Control the URL structure of your site.", |
| 14 | + " * Customize your site's sitemap.", |
| 15 | + " * Extend [dynamic pages](https://support.wix.com/en/article/content-manager-about-dynamic-pages) to include subpages that use different data.", |
16 | 16 | "",
|
17 |
| - " The functions are named with the following convention:", |
| 17 | + "The API gives you access to the following:", |
| 18 | + " * Requests to certain pages on your site and routing responses for those pages.", |
| 19 | + " * Sitemap requests and responses.", |
| 20 | + " * Hooks to control the flow of the data used to display pages returned by the router or sitemap. Hooks are often used when working with the code for [dynamic pages](https://support.wix.com/en/article/velo-about-data-hooks-for-dynamic-pages).", |
18 | 21 | "",
|
19 |
| - " ``` javascript", |
20 |
| - " export function <router prefix>_<function name>()", |
21 |
| - " ```", |
| 22 | + "Code using the Routers API is stored in the **routers.js** file in the backend code section the Velo Sidebar. You shouldn't create this file manually.", |
| 23 | + "The file is created automatically when you [add a router](https://support.wix.com/en/article/velo-creating-a-router#add-a-router) to your site.", |
22 | 24 | "",
|
23 |
| - " These are not functions that you call in your code, rather they are functions", |
24 |
| - " that you define. They are called when your users browse to a URL that is handled", |
25 |
| - " by a router as described below.", |
| 25 | + "To use the [`router()`](wix-router/router) and [`sitemap()`](wix-router/sitemap) functions in the **routers.js** file, use the following convention:", |
26 | 26 | "",
|
27 |
| - " For example, the following code creates a router on the myRouter [prefix](#prefixes) that", |
28 |
| - " shows a page when the path begins with the word \"good\" and returns a 404 in", |
29 |
| - " all other cases.", |
| 27 | + "```js", |
| 28 | + "export function <router prefix>_<function name>()", |
| 29 | + "```", |
30 | 30 | "",
|
31 |
| - " ```javascript", |
32 |
| - " import {ok, notFound} from \"wix-router\";", |
| 31 | + "To import the other API functions into the **routers.js** file, use the following syntax:", |
33 | 32 | "",
|
34 |
| - " export function myRouter_Router(request) {", |
| 33 | + "```js", |
| 34 | + "import { <function-name> } from 'wix-router';", |
| 35 | + "```", |
35 | 36 | "",
|
36 |
| - " // URL looks like:", |
37 |
| - " // https://mysite.com/myRouter/good", |
38 |
| - " // or:", |
39 |
| - " // https://user.wixsite.com/mysite/myRouter/good", |
40 |
| - " const status = request.path[0];", |
| 37 | + "## Terminology", |
41 | 38 | "",
|
42 |
| - " if(status === \"good\") {", |
43 |
| - " // Show a page", |
44 |
| - " return ok(\"myRouter-page\");", |
45 |
| - " }", |
46 |
| - " else {", |
47 |
| - " // Return 404", |
48 |
| - " return notFound();", |
49 |
| - " }", |
50 |
| - " }", |
51 |
| - " ```", |
52 |
| - "", |
53 |
| - " ### Code Router", |
54 |
| - " Code your own [`router()`](#router) and [`sitemap()`](#sitemap) functions for a", |
55 |
| - " [router](https://support.wix.com/en/article/routers) that handles all incoming", |
56 |
| - " requests with a specified URL [prefix](#prefixes). Your code decides what actions to", |
57 |
| - " perform, what responses to return, where to route the request, and what data", |
58 |
| - " to pass to pages.", |
59 |
| - "", |
60 |
| - " You might want to use a router to:", |
61 |
| - "", |
62 |
| - " + Display a dynamic page using content from any data source.", |
63 |
| - " + Customize your URLs to make them more meaningful and yield better SEO results.", |
64 |
| - " + Authenticate users and then display content just for them.", |
65 |
| - " + Return custom HTTP response codes.", |
66 |
| - "", |
67 |
| - "", |
68 |
| - " ### Data Binding Router Hooks", |
69 |
| - " When a request comes in for a page that a router handles, either a code router", |
70 |
| - " or a dynamic page, you can add [data binding router hooks](https://support.wix.com/en/article/data-binding-router-hooks)", |
71 |
| - " to intercept the process of the data getting bound to the page at certain", |
72 |
| - " points and insert additional logic.", |
73 |
| - "", |
74 |
| - " The hooks you can use are listed here in the order they are triggered:", |
75 |
| - "", |
76 |
| - " + [`beforeRouter`](wix-router/beforeRouter) - Before the data binding router logic.", |
77 |
| - " + [`customizeQuery`](wix-router/customizeQuery) - As the data binding router prepares a data query.", |
78 |
| - " + [`afterRouter`](wix-router/afterRouter) - After the data binding router completes its logic, but before the page is displayed.", |
79 |
| - " + [`afterSitemap`](wix-router/afterSitemap) - After the data binding sitemap function completes preparing the list of urls.", |
80 |
| - "", |
81 |
| - "", |
82 |
| - " ### Prefixes", |
83 |
| - " When using the `wix-router` API you often need to know the prefix of your code router", |
84 |
| - " or dynamic pages. You can find prefixes as follows:", |
85 |
| - "", |
86 |
| - " + **Code router**:", |
87 |
| - "", |
88 |
| - " 1. Go to in the Page Code's Router Pages section of the Velo Sidebar.", |
89 |
| - "", |
90 |
| - " 1. Click the ellipsis  icon that appears when you hover over the title of the router's grouped router pages.", |
91 |
| - "", |
92 |
| - " 1. Click **Change Router**.", |
93 |
| - "", |
94 |
| - " The router's prefix is displayed.", |
95 |
| - "", |
96 |
| - "", |
97 |
| - " + **Dynamic pages**:", |
98 |
| - "", |
99 |
| - " 1. Go to in the Page Code's Dynamic Pages section of the Velo Sidebar.", |
100 |
| - "", |
101 |
| - " 1. Click the ellipsis  icon that appears when you hover over the dynamic page.", |
102 |
| - "", |
103 |
| - " 1. Click **Settings**.", |
104 |
| - "", |
105 |
| - " The **Page Info** tab shows the page URL. The prefix is the", |
106 |
| - " first editable section of the URL up until the first forward slash (/)." ], |
| 39 | + " * **Router**: Part of the code on your site that receives requests for specific URLs and handles which page is ", |
| 40 | + " served and what data is included in that page.", |
| 41 | + " * **Sitemap**: A model of a site's content structure, designed to help both users and search engines navigate the site.", |
| 42 | + " * **Data binding router hooks**: Functions that run before, during, and after data is included in ", |
| 43 | + " the pages that the router and sitemap functions return. Router hooks are often used when working with [dynamic pages](https://support.wix.com/en/article/velo-about-data-hooks-for-dynamic-pages). The API includes 4 hooks:", |
| 44 | + " * [`beforeRouter`](wix-router/beforeRouter)", |
| 45 | + " * [`customizeQuery`](wix-router/customizeQuery)", |
| 46 | + " * [`afterRouter`](wix-router/afterRouter)", |
| 47 | + " * [`afterSitemap`](wix-router/afterSitemap)" ], |
107 | 48 | "links": [],
|
108 | 49 | "examples": [],
|
109 | 50 | "extra":
|
|
142 | 83 | [ "wix-router.WixRouterResponse" ] },
|
143 | 84 | "doc": "Fulfilled - A router response, either the response received or a new response." },
|
144 | 85 | "locations":
|
145 |
| - [ { "lineno": 266, |
| 86 | + [ { "lineno": 209, |
146 | 87 | "filename": "router.js" } ],
|
147 | 88 | "docs":
|
148 | 89 | { "summary": "Registers a hook that is called after a router.",
|
|
257 | 198 | [ "wix-router.WixRouterSitemapEntry" ] } ] },
|
258 | 199 | "doc": "Fulfilled - A sitemapEntries array." },
|
259 | 200 | "locations":
|
260 |
| - [ { "lineno": 322, |
| 201 | + [ { "lineno": 265, |
261 | 202 | "filename": "router.js" } ],
|
262 | 203 | "docs":
|
263 | 204 | { "summary": "Registers a hook that is called after a sitemap is created.",
|
|
323 | 264 | [ "wix-router.WixRouterResponse" ] },
|
324 | 265 | "doc": "Fulfilled - Which page to display, redirect to, or which HTTP status code to respond with." },
|
325 | 266 | "locations":
|
326 |
| - [ { "lineno": 218, |
| 267 | + [ { "lineno": 161, |
327 | 268 | "filename": "router.js" } ],
|
328 | 269 | "docs":
|
329 | 270 | { "summary": "Registers a hook that is called before a router.",
|
|
424 | 365 | { "type": "wix-data.WixDataQuery",
|
425 | 366 | "doc": "A wix-data query." },
|
426 | 367 | "locations":
|
427 |
| - [ { "lineno": 357, |
| 368 | + [ { "lineno": 300, |
428 | 369 | "filename": "router.js" } ],
|
429 | 370 | "docs":
|
430 | 371 | { "summary": "Registers a hook that is called after a route is resolved by the data binding router, but before the wix-data query is executed.",
|
|
491 | 432 | [ "wix-router.WixRouterResponse" ] },
|
492 | 433 | "doc": "Fulfilled - A response object with HTTP status code 403." },
|
493 | 434 | "locations":
|
494 |
| - [ { "lineno": 439, |
| 435 | + [ { "lineno": 382, |
495 | 436 | "filename": "router.js" } ],
|
496 | 437 | "docs":
|
497 | 438 | { "summary": "Returns a response with a status code 403 (Forbidden) and instructs the router to show a 403 page.",
|
|
530 | 471 | [ "wix-router.WixRouterResponse" ] },
|
531 | 472 | "doc": "Fulfilled - The router response." },
|
532 | 473 | "locations":
|
533 |
| - [ { "lineno": 502, |
| 474 | + [ { "lineno": 445, |
534 | 475 | "filename": "router.js" } ],
|
535 | 476 | "docs":
|
536 | 477 | { "summary": "Returns a response that instructs the router to continue.",
|
|
570 | 511 | [ "wix-router.WixRouterResponse" ] },
|
571 | 512 | "doc": "Fulfilled - A response object with HTTP status code 404." },
|
572 | 513 | "locations":
|
573 |
| - [ { "lineno": 420, |
| 514 | + [ { "lineno": 363, |
574 | 515 | "filename": "router.js" } ],
|
575 | 516 | "docs":
|
576 | 517 | { "summary": "Returns a response with a status code 404 (Not Found) and instructs the router to show a 404 page.",
|
|
599 | 540 | "extra":
|
600 | 541 | { } },
|
601 | 542 | { "name": "ok",
|
602 |
| - "labels": |
603 |
| - [ "changed" ], |
| 543 | + "labels": [], |
604 | 544 | "nameParams": [],
|
605 | 545 | "params":
|
606 | 546 | [ { "name": "Page",
|
|
625 | 565 | [ "wix-router.WixRouterResponse" ] },
|
626 | 566 | "doc": "Fulfilled - The router response object." },
|
627 | 567 | "locations":
|
628 |
| - [ { "lineno": 391, |
| 568 | + [ { "lineno": 334, |
629 | 569 | "filename": "router.js" } ],
|
630 | 570 | "docs":
|
631 | 571 | { "summary": "Returns a response with a status code 200 (OK) and instructs the router to show the selected page.",
|
|
745 | 685 | [ "wix-router.WixRouterResponse" ] },
|
746 | 686 | "doc": "Fulfilled - The redirect response object." },
|
747 | 687 | "locations":
|
748 |
| - [ { "lineno": 458, |
| 688 | + [ { "lineno": 401, |
749 | 689 | "filename": "router.js" } ],
|
750 | 690 | "docs":
|
751 | 691 | { "summary": "Returns a response with a status code of 301 (Moved Permanently) or 302 (Found) and instructs the router to redirect to the given URL.",
|
|
800 | 740 | [ "wix-router.WixRouterResponse" ] },
|
801 | 741 | "doc": "Fulfilled - Which page to display, redirect to, or which HTTP status code to respond with." },
|
802 | 742 | "locations":
|
803 |
| - [ { "lineno": 104, |
| 743 | + [ { "lineno": 47, |
804 | 744 | "filename": "router.js" } ],
|
805 | 745 | "docs":
|
806 | 746 | { "summary": "Function containing routing logic for a given URL prefix.",
|
|
1013 | 953 | [ "wix-router.WixRouterResponse" ] },
|
1014 | 954 | "doc": "Fulfilled - A response object with the specified HTTP status." },
|
1015 | 955 | "locations":
|
1016 |
| - [ { "lineno": 482, |
| 956 | + [ { "lineno": 425, |
1017 | 957 | "filename": "router.js" } ],
|
1018 | 958 | "docs":
|
1019 | 959 | { "summary": "Returns a response with the specified HTTP status code with an optional message.",
|
|
1066 | 1006 | [ "wix-router.WixRouterSitemapEntry" ] } ] },
|
1067 | 1007 | "doc": "Fulfilled - An array of sitemap entries." },
|
1068 | 1008 | "locations":
|
1069 |
| - [ { "lineno": 171, |
| 1009 | + [ { "lineno": 114, |
1070 | 1010 | "filename": "router.js" } ],
|
1071 | 1011 | "docs":
|
1072 | 1012 | { "summary": "Function containing sitemap logic for a given URL prefix.",
|
|
0 commit comments