beforeRouter( )


Registers a hook that is called before a router.

The beforeRouter hook is a data binding router hook that is triggered before the router with the specified prefix has bound the data to the page. The router can be a code router or the data binding router that binds data to a dynamic page.

The beforeRouter() function is not a function that you call from your code. You define the function in a file named routers.js in the Code File's Backend section of the Velo Sidebar. The function is called as described above.

Use this hook with a code router 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.

The function receives a WixRouterRequest object containing information about the incoming request.

The function returns a WixRouterResponse object that causes the router to continue its routing, or respond with an HTTP response code.

Typically, the response is created using one of the next(), forbidden(), notFound(), redirect(), or sendStatus() functions.

Method Declaration
Copy
Method Parameters
requestWixRouterRequestRequired

The routing request.

Returns
Return Type:Promise<WixRouterResponse>
Did this help?