Create Dynamic Page Hooks

You create dynamic page hooks to add custom logic during the page routing and loading process. Use hooks to validate requests, modify data queries, customize responses, or update sitemaps for dynamic pages.

Before you begin

Make sure you have:

  • A dynamic page set up.
  • A backend routers.js file.

Add a beforeRouter hook

To add a beforeRouter() hook on dynamic pages with the listings prefix, add the following code to your routers.js file. A beforeRouter hook needs to return a router response object.

This hook restricts admin pages to visitors with the admin role:

Copy

Add a customizeQuery hook

To add a customizeQuery() hook on dynamic pages with the listings prefix, add the following code to your routers.js file. A customizeQuery hook needs to return a data query object.

This hook shows only active real estate listings to non-admin visitors:

Copy

Add an afterRouter hook

To add an afterRouter() hook on dynamic pages with the listings prefix, add the following code to your routers.js file. An afterRouter hook needs to return a router response object.

This hook redirects unavailable listings and uses custom templates for featured listings:

Copy

See also

Did this help?