Im having issues with laravel route,
Im making a multiple react projects which uses react-router-dom and I want them to be separate instead on one project build
Below is the webpack setup to generate 2 separate folder of react project:
mix.webpackConfig({
resolve: {
alias: {
'@': path.resolve(__dirname, 'resources', 'js'),
'@admin': path.resolve(__dirname, 'resources', 'js', 'Application', 'Admin'),
'~': path.resolve(__dirname, 'resources', 'sass'),
// '@components': '/resources/assets/js/components'
}
}
})
.react('resources/js/Application/Admin/app.js', 'public/js/Admin')
.react('resources/js/Application/LandingPage/app.js', 'public/js/LandingPage').sourceMaps()
.sass('resources/sass/app.scss', 'public/css');
On the laravel route, this is my configuration:
Route::get('/', function () {
return view('lading-page');
});
Route::get('/admin', function () {
return view('admin');
});
Root.jsx
import * as React from 'react';
import ReactDOM from 'react-dom';
import Signin from './Pages/Signin'
import Auth from './Pages/Auth/App'
import Dashboard from './Pages/Auth/Dashboard'
import Users from './Pages/Auth/Users'
import PageNotFound from './Pages/PageNotFound'
import { BrowserRouter, Routes, Route } from "react-router-dom";
function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Signin />} />
<Route path="/dashboard" element={<Auth />}>
<Route path="" element={<Dashboard />} />
<Route path="users" element={<Users />} />
</Route>
<Route path="*" element={<PageNotFound />} />
</Routes>
</BrowserRouter >
);
}
ReactDOM.render(<App />, document.querySelector('#app'));
The landing page is working fine,
But when I use the admin route it says 404 not found which is the react-router-dom 404 handler not Laravel route handler
My question is, to solve this issue? Is there a way or does Laravel React support's Laravel routing to render specific view ?
Just got solve the issue:
So in my case I was using BrowserRouter on react route, this method will definitely edit the URL when routing and this method is the same as laravel route, thats the conflict happen.
To fix this have to use HashRouter which will add #/ to the routes and not causing conflicts to Laravel route