AngularJS html5Mode enabled creates reload issue
We have a Lumen app with an AngularJS front end. We are using front-end routing and we removed the hashtag in the url by setting html5Mode to true.
The issue is that when we try to reload the page or type the address without the hashtag, we get an error:
NotFoundHttpException in Application.php line 1244
In our nginx config file, we have this line (we're using prerender.io to cache our pages for SEO):
location / {
try_files $uri $uri/ /index.php?$query_string @prerender;
}
Any help to fix the reload issue would be greatly appreciated. Please let me know if you need any additional information.
I got my answer from this question:
http://stackoverflow.com/questions/30688090/laravel-5-angularjs-html5-mode
The question was for Laravel but the answer works for Lumen if you change it a bit.
The Laravel routes in the answer above look like this:
Route::get('/', function () {
return View::make('index');
});
Route::get('{all}', function () {
return View::make('index');
});
While my Lumen routes are like this:
$app->get('/', 'AppController@index');
$app->get('{all}', 'AppController@index');
Obviously you don't have to go in the controller if you don't want to but that's how I have mine set up.
Please or to participate in this conversation.