Saturday, 29 April 2017

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 entry file for React.

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?



via John

No comments:

Post a Comment