Velo: About Routers
You might want to use a router to:
- Display a dynamic page using content from any data source.
- Customize your URLs to make them more meaningful and yield better SEO results.
- Authenticate users and then display content just for them.
- Return custom HTTP response codes.
URL Prefix
The prefix is the part of the URL shown in bold in the following examples:
- Premium site: https://domain.com/prefix/category/item
- Free site: https://user.wixsite.com/yoursite/prefix/category/item
Routing Code
They are named with the following convention:
<router prefix>_Router(request)
<router prefix>_Sitemap(sitemapRequest)
router()
The router()
function is where page requests with the defined prefix are sent. The router receives a WixRouterRequest
object containing information about the incoming request. The function then decides what to do with the request and returns the appropriate WixRouterResponse
. Typically, the router()
function will decide which page to show (if any) and what data to pass to the page. The response is then sent using the forbidden()
, notFound()
, ok()
, redirect()
, or sendStatus()
functions.
sitemap()
The sitemap()
function is where sitemap requests are handled. You can use this function to make sure search engines can find the links to your router's pages. Each WixSitemapEntry
includes information about a page, such as its URL, title, and name.
The sitemap()
function is also used to populate the items preview widget, allowing you to switch between URLs in preview mode.
Router Data
Your router()
function may choose to send data to the pages it routes to. You can access that data in the frontend page code using the getRouterData()
function of the wix-window
module.