Laravel返回除路由以外的任何地址的页面


Laravel return the page on any address except from routes

我有一个Laravel应用程序的路由列表。现在,我想为所有未列出的路由返回与/上返回的页面相同的页面。即

/hello/world <-> binded to "Hello world" page
/blah/blah <-> binded to "Blah Blah" p

现在,无论什么用户请求(GET(以及请求中有多少斜杠(/asdfda/sadfasdf/asdfasdfeafsadfsdaasdfadsfasd/adsfsdaf(,我都希望返回相同的页面。不过,我不希望它是404,因为我想保持这一合法途径。


我试过

Route::get('{all?}', [
    'as' => 'spa.index',
    'uses' => 'SPAController@index',
]);

但只有在没有斜线的情况下,这才有效。


有人知道怎么做吗?

好吧,我自己找到了解决方案。我会把这个问题留给子孙后代。无论用户请求的路线是什么,这都将返回相同的页面

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);
}