I have a project with both a React frontend and a Laravel backend. I want to achieve the following routing logic:
When a user visits www.example.com, it should load the React frontend (like an SPA).
When the user visits www.example.com/admin/login, it should route to Laravel’s Blade template for admin login.
I’m hosting the project on Hostinger (shared hosting) and need help setting up this structure correctly.
// Catch-all route for React frontend
Route::get('/', function () {
return file_get_contents(public_path('react-app/public/index.html'));
});
// Catch React frontend routes (e.g., /about, /contact, etc.)
Route::get('/{any}', function () {
return file_get_contents(public_path('react-app/public/index.html'));
})->where('any', '^(?!admin).*');
I write like that but I want to know that is this good approach?
I mean can it create problems in future and can it create problems to frontend?