Answer the question
In order to leave comments, you need to log in
How to properly use React Router in Laravel?
The React app is right in the Laravel project, I use Laravel Mix to make sure everything works fine.
If you enter the site from the main page and follow the links, then everything works fine, but if you go to the same address, not the link from the site, but, for example, by entering the address manually, then a Laravel error 404 is displayed.
PS:
Found somewhere the solution to the problem, now when you go to an address that exists in react, but is missing in Laravel, react is displayed, but its main page.
Here is the web.php file code
Route::get('/{path?}', [
'uses' => 'App\Http\Controllers\[email protected]',
'as' => 'react-router.index',
'where' => ['path' => '.*'],
]);
class ReactRouterController extends Controller
{
public function index()
{
return view('welcome');
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question