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

151
Visualizações
react-router-dom v6 renders only default route

I'm starting a new project using React Router Dom v6 and I'm in trouble with one of the first steps: setting the routes for the App.

I just created two pages: AuthPage and DashboardPage and I would like to be able of rendering both of them if, from the browser, I navigate to:

  • localhost:PORT/ : should render DashboardPage
  • localhost:PORT/auth: should render AuthPage

but right no the only page rendered is DashboardPage even if I try to navigate to non-existing routes.

This is my code so far:

main.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>
)

App.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

routes.ts

export const routes = {
  auth: {
    url: '/auth'
  },
  dashboard: {
    url: '/'
  },
  notFound: {
    url: '*'
  }
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Use BrowserRouter instead of 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 Relatório

0

As I know, exact option doesn't supported in react-router v6. Try to use index option.

<Route path="/*">
  <Route index element={< DashboardPage />} />
  <Route path={routes.auth.url} element={<AuthPage />} />
  // ... other routes
</Route>
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