在尝试捕捉非Laravel路线并呈现Angular视图时,我遇到了混合Laravel和Angular路由的问题。
当我在app \ http \ route.php中添加了缺少的方法时,我收到了以下错误:
Facade.php第216行中的FatalErrorException:调用未定义的方法Illuminate \ Foundation \ Application :: missing()
我知道这对于laravel 5或者down版本可以正常工作,但是我目前没有使用laravel 5.2,那么如何在laravel 5.2中编码?任何解决方案?
route.php看起来像:
<?php // app/routes.php
// HOME PAGE ===================================
// I am not using Laravel Blade
// I will return a PHP file that will hold all of our Angular content
Route::get('/', function() {
View::make('index'); // will return app/views/index.php
});
// API ROUTES ==================================
Route::group(['prefix' => 'api'], function() {
// Angular will handle both of those forms
// this ensures that a user can't access api/create or api/edit when there's nothing there
Route::resource('comments', 'CommentController',
['only' => ['index', 'store', 'destroy']]);
});
// CATCH ALL ROUTE =============================
// all routes that are not home or api will be redirected to the frontend
// this allows angular to route them
App::missing(function($exception) {
return View::make('index');
});
答案 0 :(得分:5)
App :: missing()。您需要自己定义一个包罗万象的路线,只需确保将其放在路线的末尾即可。 PHP 强>:
Route::any('{catchall}', function() {
//some code
})->where('catchall', '.*');