我正在创建一个使用Laravel 4作为后端和AngularJS作为前端的RESTful应用程序。我想使用来自Angular的路由。
routes.php
在laravel中这样设置(使用一组/ api,但这不是必需的)
Route::any('{all}', function ($uri) {
return View::make('index');
})->where('all', '.*');
我在Angular的路线是
$routeProvider.
when('/', {
templateUrl: 'views/test.html',
controller: 'homeCtrl'
}).
when('/test', {
templateUrl: 'views/test.html',
controller: 'homeCtrl'
}).
when('/test/:id', {
templateUrl: 'views/test.html',
controller: 'homeCtrl'
}).
otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode(true);
我定义<base href="/"/>
在index.php
我的xampp中的DocumentRoot已放入DocumentRoot "C:/xampp/htdocs/laravel/public"
(因此Laravel中的公用文件夹)
当我击中localhost/test
一切正常。但是,当我尝试访问时localhost/test/1
,所有内容都index.php
从Laravel视图作为文件加载,如下所示。
有谁解决这个问题?我是否应该在中创建正则表达式routes.php
,以容纳所有(.js,.jpg,...)扩展名(我认为这不是一个好主意)?还是应该更改.htaccess
文件?
我找到了这个问题的解决方案,并将缺少在Laravel中捕获的路线更改为此,一切都很好。
App::missing(function ($exception) {
return Redirect::to('/#/' . Request::path());
});
问题是
#
作为前缀。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句