Laravel 5 + AngularJS html5Mode [英] Laravel 5 + AngularJS html5Mode
问题描述
我正在使用Laravel 5和AngularJS开发一个项目。我要启用
I'm developing a project using Laravel 5 and AngularJS. I want to enable
$locationProvider.html5Mode(true);
并停止重新加载页面。当我将其设置为false并访问链接时,页面不会重新加载。
and stop the page from reloading. The page doesn't reload when I set it to false and visit a link.
这是我的 route.php
Route::get('/', function () {
return View::make('index');
});
角度代码
app.config(function($routeProvider, $locationProvider) {
$routeProvider.when('/', {
templateUrl: 'views/feed.html',
controller: 'fdController'
}).when('/collections', {
templateUrl : 'views/collections.html',
controller: 'clController'
}).otherwise({
redirectTo : '/'
});
$locationProvider.html5Mode(true);
});
当我访问链接时 html5Mode(false)
localhost:8000 /#/ - > localhost:8000 /#/ feed
页面不刷新
When I visit a link html5Mode(false)
localhost:8000/#/ -> localhost:8000/#/feed
the page doesn't refresh
当 html5Mode(true)$ c时$ c>我访问
localhost:8000 / - > localhost:8000 / feed
,页面刷新,我收到此错误:
When html5Mode(true)
and I visit
localhost:8000/ -> localhost:8000/feed
, the page refreshes and I get this error:
抱歉,您的页面是无法找到。
Sorry, the page you are looking for could not be found.
推荐答案
我将route.php改为
I changed my route.php to
Route::get('/', function () {
return View::make('index');
});
Route::get('{all}', function () {
return View::make('index');
});
并添加了基数< base href =/>
到我的index.php
现在一切正常,页面也不刷新。
And added a base <base href="/">
to my index.php
Everything works now and the page doesn't refresh.
这篇关于Laravel 5 + AngularJS html5Mode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!