Question: **How to easily list all routes that we have defined in our application with Zend Framework** 2?

By "routes" I mean those which are defined in:

`module/[moduleName]/config/module.config.php`

under

```
'router' => array(
    'routes' => array(
        ...
    )
)

```

I need to list them all but I can't figure out how to do this easily and nor the documentation nor the forums helped me by now.

Answer: 
You can find the complete (merged) config or dump the Router itself. There is no way to export all route objects, so there I've to disappoint you.

To get the complete config, get it from the service locator:

```
// $sl instanceof Zend\ServiceManager\ServiceManager

$config = $sl->get('COnfig');
$routes = $config['router']['routes'];

```

If you want to view all routes just for debugging purposes, you can use `var_dump` or similar on the router object:

```
// $sl instanceof Zend\ServiceManager\ServiceManager

$router = $sl->get('Router');
var_dump($router);

```

To get route instances you can build the routes yourself using the route plugin manager, but I am not sure that's the way you want to go...
You can get a list of routes from the router using the following code snippet. `$mvcEvent` is an instance of `Zend\Mvc\MvcEvent` and `TreeRouteStack` is `Zend\Router\Http\TreeRouteStack`.

```php
$router = $mvcEvent->getRouter();
$routes = (array) $router->getRoutes();
$routes = array_values($routes);
$routes = count($routes) > 0 ? array_keys($routes[0]) : [];

```