Issue
I’ve got a small issue with routing with AngularJS using Laravel. When I have a url like www.example.com/blog
and I refresh, it will load fine under the AngularJS UI Router, however, when I have www.example.com/blog/1
and I refresh it shows the Laravel-side 404.
I have my web.php
set-up like this:
Route::get("/", function(){
return view("index");
});
Route::get('/{all}', function () {
return view('index');
});
I also have $location.html5Mode(true);
in AngularJS and also my <base />
and the routes are all defined accordingly.
Can anyone shed some light on this?
Solution
For future reference and people coming here from search results.
Route::get('/{all}', function(){
return view('index');
})->where(['all' => '(.*)'])
A where is needed to catch all after the initial / This isn’t explicitly noted in the documentation: https://laravel.com/docs/5.6/routing#parameters-regular-expression-constraints
Answered By – Tuim
Answer Checked By – Terry (AngularFixing Volunteer)