Laravel return 除来自路由之外的任何地址上的页面
Laravel return the page on any address except from routes
我的 Laravel 应用程序有一个路由列表。现在,我想 return 与 return 在 /
上编辑的页面相同,用于所有未列出的路线。即
/hello/world <-> binded to "Hello world" page
/blah/blah <-> binded to "Blah Blah" p
现在,无论用户请求什么(GET),请求中有多少斜线(/asdfda/sadfasdf/asdfasdf
,eafsadfsda
,asdfadsfasd/adsfsdaf
),我都想return 同一页。不过,我不希望它成为 404,因为我想保持这条合法路线。
我试过了
Route::get('{all?}', [
'as' => 'spa.index',
'uses' => 'SPAController@index',
]);
但这只有在没有斜杠的情况下才有效。
有人知道怎么做吗?
好吧,我自己找到了解决办法。我会为后代保留这个问题。这将 return 相同的页面,无论用户请求什么路由
Route::get('{all?}', [
'as' => 'spa.index',
'uses' => 'SPAController@index',
])->where('all', '([A-z\d-\/_.]+)?');
Route::get('/{foo}/{bar}', [
'as' => 'spa.index',
'uses' => 'SPAController@index',
]);
并在 SPAController 和操作索引中添加:
public function index($foo,$bar){
return view($foo.' '.$bar);
}
我的 Laravel 应用程序有一个路由列表。现在,我想 return 与 return 在 /
上编辑的页面相同,用于所有未列出的路线。即
/hello/world <-> binded to "Hello world" page
/blah/blah <-> binded to "Blah Blah" p
现在,无论用户请求什么(GET),请求中有多少斜线(/asdfda/sadfasdf/asdfasdf
,eafsadfsda
,asdfadsfasd/adsfsdaf
),我都想return 同一页。不过,我不希望它成为 404,因为我想保持这条合法路线。
我试过了
Route::get('{all?}', [
'as' => 'spa.index',
'uses' => 'SPAController@index',
]);
但这只有在没有斜杠的情况下才有效。
有人知道怎么做吗?
好吧,我自己找到了解决办法。我会为后代保留这个问题。这将 return 相同的页面,无论用户请求什么路由
Route::get('{all?}', [
'as' => 'spa.index',
'uses' => 'SPAController@index',
])->where('all', '([A-z\d-\/_.]+)?');
Route::get('/{foo}/{bar}', [
'as' => 'spa.index',
'uses' => 'SPAController@index',
]);
并在 SPAController 和操作索引中添加:
public function index($foo,$bar){
return view($foo.' '.$bar);
}