由于附加到路由堆栈的路由存储在优先列表 https://github.com/zendframework/zf2/blob/release-2.1.3/library/Zend/Mvc/Router/SimpleRouteStack.php#L49,第一个匹配的路线将获胜。
路线附加到主路线上priority setting https://github.com/zendframework/zf2/blob/release-2.1.3/library/Zend/Mvc/Router/SimpleRouteStack.php#L252-L280。较高优先级意味着首先检查路由。默认情况下,将读取第一个附加路由(如果它们都具有相同的优先级或根本没有优先级)。
'route-catchall' => array(
'type' => 'regex',
'options' => array(
'regex' => '/api/v1/.*',
'defaults' => array(
'controller' => 'IndexController',
'action' => 'apiCatchAll',
),
),
'priority' => -1000,
),
'route-test1' => array(
'type' => 'literal',
'options' => array(
'route' => '/api/v1/route1',
'defaults' => array(
'controller' => 'IndexController',
'action' => 'apiRoute1',
),
),
'priority' => 9001, // it's over 9000!
),
在这个例子中,route-test1
由于优先级高,将首先匹配。