> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: About Data Hooks for Dynamic Pages

## Article: About Data Hooks for Dynamic Pages

## Article Link: https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/hooks/about-data-hooks-for-dynamic-pages.md

## Article Content:

# Velo: About Data Hooks for Dynamic Pages



When a request comes in for one of your dynamic pages, [a router uses the URL of the request](https://support.wix.com/en/article/cms-about-dynamic-pages#dynamic-item-pages) to decide which page to show and what data to bind to the page's dataset. You can add a data binding router hook to intercept this process at certain points and insert additional logic. Some hooks can be used with [router pages](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/routers/about-routers.md) as well.

**Note:** If you duplicate a dynamic page and change a router prefix, you must also update the hook function.

## Router Hooks

After defining a router for your site, you can define data binding router hooks in **routers.js** located in the Public & Backend section of the Code sidebar (Wix Studio), or the Code sidebar (Wix Editor). 

**Note:** To define data hooks, you must first create a router and add it your site. See how to create a router in [Wix Studio](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/routers/create-a-router.md), or in the [Wix Editor](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/routers/create-a-router.md). 

The hook functions are named with the following convention:

    <router prefix>_<hook name>()

The router prefix is the first part of the URL you chose when creating your dynamic page. You can find the URL of your dynamic page in the page's settings. 

For example, if you have a page with the URL `/dishes/name` and you want to create a `beforeRouter` hook, the function would look like this:

    export function dishes_beforeRouter(request) {
      // function code
    }

The hooks you can register are listed here in the order they run:

*   beforeRouter
*   customizeQuery
*   afterRouter

To learn more about the hook functions, see the [Router API reference](http://wix.to/94BuAAs/wix-router.html).

You can also register [data hooks](https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/hooks/about-data-hooks.md) that run code before or after certain interactions with your site's collections. If you’ve done so, the data hooks will run between `customizeQuery()` and `afterRouter()`.

### beforeRouter()

This hook is triggered before the router goes to the requested page. You can use this hook to route requests to a different page or return an error response. For example, you can check who is requesting the page and then decide based on the user's role whether to let the router continue to the next step or to return an error type response code.

### customizeQuery()

This hook is triggered before the page's data query is executed. You can use this hook to further refine or change the query that will determine what data is bound to your page's dataset. For example, you can filter the query to only return items that have a status field set to active.

### afterRouter()

This hook is triggered after the router has bound the data, but before the page is displayed. You can use this hook to change the router's response based on the data that was retrieved. For example, you can have two versions of a page, one for portrait oriented images and another for landscape oriented ones. After the image is pulled from the database, you can show the page that corresponds to the image's orientation.