laravel 5 + angularjs HTML5模式 [英] laravel 5 + angularjs html5 mode
问题描述
我正在开发使用laravel 5 angularjs的项目。我想启用结果
$ locationProvider.html5Mode(真);
从重装停止页面。当我把它设置为false的页面不会重新加载并访问链接。
I'm developing a project using laravel 5 and angularjs. I want to enable
$locationProvider.html5Mode(true);
and stop the page from reloading. The page doesn't reload when I set it to false and visit a link.
下面是我的route.php
Here is my route.php
Route::get('/', function () {
return View::make('index');
});
角code
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(假)
本地主机:8000 /#/ - >本地主机:8000 /#/饲料,网页不刷新
When i visit a link html5mode(false) localhost:8000/#/ -> localhost:8000/#/feed , the page doesn't refresh
当html5mode设置为true,我参观
本地主机:8000 / - >本地主机:8000 /饲料,页面刷新,我得到这个错误
很抱歉,您要查找的页面无法找到。
When html5mode is set to 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');
});
和加入碱<基本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 HTML5模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!