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

167
Visualizações
Cannot get property 'location' of undefined. React Router

I am trying to set up React Router in an application using MERN stack and am getting the error 'Cannot get property "location" of undefined'.

Below is where I am setting the react view engine in my express app and calling the index view where my Router is being defined.

app.set('views', __dirname + '/views');
app.engine('jsx', require('express-react-views').createEngine())
app.set('view engine', 'jsx')

app.get('/', (req,res) => {
  res.render('index.jsx')
})

here is the index.jsx file:

if(typeof window !== 'undefined') {
    ReactDOM.render(<App />, document.getElementById("root"));
}

Here is the App component.

import React from 'react'
import ReactDOM from 'react-dom'
import { Router, Route, IndexRoute, hashHistory } from 'react-router'
import Home from './components/home.jsx'
import App from './app.jsx'
import ContactsIndex from './components/contacts/contactsIndex.jsx'

const AppRouter = () => {
  return (
    <Router history={hashHistory}>
      <Route path='/' component={App}>

      </Route>
    </Router>
  )
}

export default AppRouter

I have seen other people with this problem who did not include a history property when defining their router. I have history included so there seems to be something else going on. Any ideas?

over 4 years ago · Santiago Trujillo
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