Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 + AngularJS html5Mode

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.

like image 438
user2595818 Avatar asked Jun 06 '15 22:06

user2595818


1 Answers

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.

like image 70
user2595818 Avatar answered Sep 30 '22 18:09

user2595818