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

164
Views
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
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!