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...
I needed to differentiate routes per module so that we can use BjyAuthorize's ACL setup respectively in different situations.

While there is more than one way to do to this such as shown by [Jurian Sluiman](https://stackoverflow.com/users/434223/jurian-sluiman) to read in all the routes (variables changed):

```php
<?php

// $this->services instanceof Zend\ServiceManager\ServiceManager

$config = $this->services->get('Config');
$routes = $config['router']['routes'];

```

You can obtain them as follows for future differentiation per module in a **function**:

```php
<?php

// $this->services instanceof Zend\ServiceManager\ServiceManager

/**
 * Load the Application's active modules.  
 * @note May need to specify additional modules that may not be 
 * loaded at this runtime.
 */
$moduleManager = $this->services->get('ModuleManager');
$moduleManager->loadModules();

// Retrieve array of module names.
$modules = $moduleManager->getModules();

// Setup a container for all active routes.
$routes = []; 

// Build array of all active routes.
foreach ($modules as $moduleName) {
    $module = $moduleManager->getModule($moduleName);
    $routes[$moduleName] = array_keys($module->getConfig()['router']['routes']);
}
// Whatever you care to do with them.
echo $routes;

```