Introduction

The Wix Router API allows you to handle certain incoming requests to your site's pages and sitemap and customize the responses.

Some things you might do with the Router API are:

  • Control the URL structure of your site.
  • Customize your site's sitemap.
  • Extend dynamic pages to include subpages that use different data.

The API gives you access to the following:

  • Requests to certain pages on your site and routing responses for those pages.
  • Sitemap requests and responses.
  • 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.

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. The file is created automatically when you add a router to your site.

To use the router() and sitemap() functions in the routers.js file, use the following convention:

Copy
1

To import the other API functions into the routers.js file, use the following syntax:

Copy
1

Get hands-on experience with the Routers API on our Hello Routers example page.

Terminology

  • Router: Part of the code on your site that receives requests for specific URLs and handles which page is served and what data is included in that page.
  • Sitemap: A model of a site's content structure, designed to help both users and search engines navigate the site.
  • Data binding router hooks: Functions that run before, during, and after data is included in the pages that the router and sitemap functions return. Router hooks are often used when working with dynamic pages. The API includes 4 hooks:
Was this helpful?
Yes
No