我正在尝试创建一些简单的SPA。如何为根页面设置通用路由?例如,在Laravel中可以做到这一点。
Route::any('{any?}', function () {
return view('index');
})->where('any','.*');
但是我不知道在Zend Framework 3中是如何产生的
这是我的解决方法
我有一个基本的“应用”模块。然后我创建了一个新模块“ Api”,这是我在模块配置中拥有的]
//module App, file: config.module.php
'routes' => [
'home' => [
'type' => Regex::class,
'options' => [
'regex' => '([^\?]+)(\?.*)?',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
'spec' => ''
],
],
],
//module Api file:config.module.php
'routes' => [
'api_index' => [
'type' => Regex::class,
'options' => [
'regex' => '/api/v1/(?<index>[a-zA-Z0-9_-]+)',
'defaults' => [
'controller' => Controller\V1\IndexController::class,
'action' => 'index',
],
'spec' => '/api/v1/%index%'
],
],
],