Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

261
Visualizações
Laravel React with react router on other route causes 404

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 ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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

https://reactrouter.com/docs/en/v6/api#hashrouter

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda