An experienced software developer with a strong background in developing award-winning web and mobile applications for diverse clients with 6+ years of industry experience.
There is a fallback method in Laravel router that calls the function you defined instead of showing 404 error so I think that is best, you can then handle 404 in your Frontend router.
// routes/web.php/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/Route::fallback(function(){returnview('app');});
An experienced software developer with a strong background in developing award-winning web and mobile applications for diverse clients with 6+ years of industry experience.
Yeah, I just add that to routes/web.php and all requests will be directed to my Frontend Router. With this, you can add other routes above and Laravel will only let the frontend handle the route when it does not recognize it.
This works perfect for / but if I was not able to make it work if your route is nested:
$router->group(['prefix'=>'admin'],function($router){// $router->fallback('AdminController@index'); // This does not for '/'$router->get('/{opt?}','AdminController@index')// This one does->where('opt','.*')->fallback();});
An experienced software developer with a strong background in developing award-winning web and mobile applications for diverse clients with 6+ years of industry experience.
Yeah...perfect for a case where most of your views are rendered by a Frontend library like React, Vue etc...it is only available in root route group, does not work in nested groups.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
There is a fallback method in Laravel router that calls the function you defined instead of showing 404 error so I think that is best, you can then handle 404 in your Frontend router.
That's definitely an option! Didn't know about this one 👍
Yeah, I just add that to routes/web.php and all requests will be directed to my Frontend Router. With this, you can add other routes above and Laravel will only let the frontend handle the route when it does not recognize it.
Nice. I will try this tomorrow. Have been using vue-router with hashes in my project so far.
This works perfect for
/
but if I was not able to make it work if your route is nested:Yeah...perfect for a case where most of your views are rendered by a Frontend library like React, Vue etc...it is only available in root route group, does not work in nested groups.