Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
react-router-dom v6 representa solo la ruta predeterminada

Estoy comenzando un nuevo proyecto usando React Router Dom v6 y tengo problemas con uno de los primeros pasos: configurar las rutas para la aplicación.

Acabo de crear dos páginas: AuthPage y DashboardPage y me gustaría poder representar ambas si, desde el navegador, navego a:

  • localhost:PORT/ : debe mostrar DashboardPage
  • localhost:PORT/auth: debe representar AuthPage

pero no, la única página representada es DashboardPage incluso si intento navegar a rutas que no existen.

Este es mi código hasta ahora:

principal.tsx

 import { createRoot } from 'react-dom/client' import { MemoryRouter as Router } from 'react-router-dom' import { ThemeProvider } from '@mui/material/styles' import { theme } from './theme' import App from './App' const root = createRoot(document.getElementById('root') as HTMLElement) root.render( <ThemeProvider theme={theme}> <Router> <App /> </Router> </ThemeProvider> )

Aplicación.tsx

 import { Route, Routes } from 'react-router-dom' import AuthPage from './pages/AuthPage' import DashboardPage from './pages/DashboardPage' import NotFoundPage from './pages/NotFoundPage' import { routes } from './routes' function App() { return ( <Routes> <Route path={routes.dashboard.url} element={<DashboardPage />} /> <Route path={routes.auth.url} element={<AuthPage />} /> <Route path={routes.notFound.url} element={<NotFoundPage />} /> </Routes> ) } export default App

rutas.ts

 export const routes = { auth: { url: '/auth' }, dashboard: { url: '/' }, notFound: { url: '*' } }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Use BrowserRouter en lugar de MemoryRouter :

 import { createRoot } from 'react-dom/client' import { BrowserRouter } from 'react-router-dom' import { ThemeProvider } from '@mui/material/styles' import { theme } from './theme' import App from './App' const root = createRoot(document.getElementById('root') as HTMLElement) root.render( <ThemeProvider theme={theme}> <BrowserRouter> <App /> </BrowserRouter> </ThemeProvider> )
about 4 years ago · Juan Pablo Isaza Report

0

Como sé, la opción exacta no es compatible con react-router v6. Trate de usar la opción de índice.

 <Route path="/*"> <Route index element={< DashboardPage />} /> <Route path={routes.auth.url} element={<AuthPage />} /> // ... other routes </Route>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!