我目前正在构建一个应用程序,我希望我的网址类似于 my-domain.com/
而不是 my-domain.com/#/
。因为我正在使用 AngularJS 构建 SPA,所以我启用了 $locationProvider
的 html5Mode
。
但是,当我转到另一个页面(例如 my-domain.com/test
)(在我的 $routeProvider
配置中定义)时,我得到 laravel 的错误页面。这不是我想要的,因为我希望 AngularJS 处理这条路线。
我环顾四周,发现了类似的东西
App::missing(function($exception)
{
return view('client/index');
});
遗憾的是,这在 Laravel 5 中不起作用。在研究了处理错误的新方法之后,我决定测试新的异常处理程序,因此在我的 App\Exceptions\Handler.php 中我这样做了:
public function render($request, Exception $e)
{
return view('client/index');
}
不幸的是,这也不起作用,因为现在它呈现一个空白页面......
有人知道如何解决这个问题吗?这是我的 Angular ngroute 配置代码:
client.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider){
$routeProvider
.when('/', {
templateUrl: '/client_partials/Homepage.html'
})
.when('/test', {
templateUrl: '/client_partials/Homepage.html'
})
.otherwise({
redirectTo : '/'
});
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');
}]);
最佳答案
路线如下:
Route::any('{path?}', function()
{
return File::get(public_path() . '/angular.html');
})->where("path", ".+");
关于javascript - Laravel 5 和 AngularJS 从 url 中删除 '#',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28681480/