Laravel 5 + AngularJS html5Mode

时间:2015-06-06 22:16:12

标签: angularjs html5 laravel-5 mode

我正在使用Laravel 5和AngularJS开发项目。我想启用

$locationProvider.html5Mode(true);

并停止重新加载页面。当我将其设置为false并访问链接时,该页面不会重新加载。

这是我的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页面无法刷新

html5Mode(true)和我访问时 localhost:8000/ -> localhost:8000/feed,页面刷新,我收到此错误:

  

抱歉,找不到您要查找的页面。

1 个答案:

答案 0 :(得分:6)

我将route.php改为

Route::get('/', function () { 
    return View::make('index'); 
});


Route::get('{all}', function () { 
    return View::make('index'); 
});

并在我的index.php中添加了一个基础<base href="/"> 现在一切正常,页面也不会刷新。