Laravel 5 + AngularJS html5Mode

偶尔善良 提交于 2019-12-01 03:30:40

问题


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.

Here is my route.php

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

Angular 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);
});

When I visit a link html5Mode(false) localhost:8000/#/ -> localhost:8000/#/feed the page doesn't refresh

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.


回答1:


I changed my route.php to

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


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

And added a base <base href="/"> to my index.php Everything works now and the page doesn't refresh.



来源:https://stackoverflow.com/questions/30688090/laravel-5-angularjs-html5mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!