---
title: "Generating Paginated Routes"
package: "PagerfantaBundle"
version: "2.x"
canonical_url: "https://www.babdev.com/open-source/packages/pagerfantabundle/docs/2.x/generating-paginated-routes"
package_supported: true
version_released: true
end_of_support: "2021-12-31T23:59:59.999Z"
notice:
  - "Version 2.x of PagerfantaBundle reached end of support on 2021-12-31."
---
# Generating Paginated Routes

When rendering a Pagerfanta view, a route generator callable is required to generate the URLs for each item in the pagination list. As of PagerfantaBundle 2.2, the route generator can be customized for use within your application if you need to adjust the routing logic.

The route generators are defined by two interfaces, with their default implementations noted below:

- `Pagerfanta\RouteGenerator\RouteGeneratorInterface` - The class type that is used to generate routes
    - `BabDev\PagerfantaBundle\RouteGenerator\RouterAwareRouteGenerator` is used by default, which uses the Symfony Routing component to generate routes
- `Pagerfanta\RouteGenerator\RouteGeneratorFactoryInterface` - A factory service that is used to generate a `RouteGeneratorInterface` at runtime
    - `BabDev\PagerfantaBundle\RouteGenerator\RequestAwareRouteGeneratorFactory` is used by default, which uses the `Symfony\Component\HttpFoundation\Request` object to attempt to set the default route name and route parameters, this creates a `RouterAwareRouteGenerator`

The Twig integration uses a `RouteGeneratorFactoryInterface` instance to create the route generator used when rendering a Pagerfanta view.

The `pagerfanta.route_generator_factory` service is available for use in your application if you need to create a route generator. You may use a compiler pass to change this service to any class meeting the interface requirements.

## `RouterAwareRouteGenerator` Options

The following options may be passed through a route generator factory when using the `BabDev\PagerfantaBundle\RouteGenerator\RouterAwareRouteGenerator` in order to customize the generated URLs:

- `routeName` - Required option (generated by the `RequestAwareRouteGeneratorFactory` if not given), the name of the route to use for the paginated URLs
- `pageParameter` - Defaults to "`[page]`", specifies the name of the routing parameter to use for the page, note that the page parameter *MUST* be wrapped in brackets (i.e. `[other_page]`) for the route generator to correctly function
- `omitFirstPage` - Defaults to `false`, a boolean value indicating whether the first page should omit the pagination parameter (if true, `?page=1` will not be part of the paginated URL for page 1 of your list)
- `routeParams` - Defaults to an empty array, an array of additional parameters to pass to the router for generating the URL
- `referenceType` - Defaults to `Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_PATH`, allows specifying the `$referenceType` parameter when calling `Symfony\Component\Routing\Generator\UrlGeneratorInterface::generate()` (this option was added in PagerfantaBundle 2.5)
