Laravel 5 + AngularJS html5Mode

I am developing a project using Laravel 5 and AngularJS. I want to enable

$locationProvider.html5Mode(true); 

and stop page reloading. The page does not reload when I set it to false and go to the 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 find the link html5Mode(false) localhost:8000/#/ -> localhost:8000/#/feed page is not updated

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 was not found.

+6
source share
1 answer

I changed my route.php to

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

And he added the base <base href="/"> to my index.php. Now everything works, and the page does not refresh.

+5
source

Source: https://habr.com/ru/post/988631/


All Articles