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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With