5

Today when I started up the iMac to continue working on the ReactJS app...it doesn't load...

What I mean by "load" is, it doesn't display the content of any page.

Error:

Uncaught TypeError: Cannot read property 'getCurrentLocation' of undefined

If you need the code of App.js and index.js here they are:

App.js:

import React, { Component } from 'react';
import Header from './pages/Header';
import Footer from './pages/Footer';

import './css/App.css';

class App extends Component {
  render() {
    return (
      <div className="App">

        <Header />

            {/*Content*/}
            <div> App Page </div>

        <Footer />

      </div>
    );
  }
}

export default App;

index.js:

import { Router, Route, History } from 'react-router';
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

// CSS
import './css/index.css';

// Pages
import About from './pages/About';
import Register from './pages/Register';
import Cart from './pages/Cart';
import Thanks from './pages/Thanks';
import Faq from './pages/Faq';
import Contact from './pages/Contact';
import Error from './pages/Error';

ReactDOM.render((
  <Router history={History}>
    <Route path="/" component={App}>
        <Route path="/pages/about" component={About}/>
        <Route path="/pages/Register" component={Register}/>
        <Route path="/pages/Cart" component={Cart}/>
        <Route path="/pages/Thanks" component={Thanks}/>
        <Route path="/pages/Error" component={Error}/>
        <Route path="/pages/Faq" component={Faq}/>
        <Route path="/pages/Contact" component={Contact}/>
    </Route>
  </Router>
), document.getElementById('root'))
3
  • console errors? Commented Mar 13, 2017 at 19:39
  • imgur.com/a/wng0C Commented Mar 13, 2017 at 19:42
  • I didn't have iMac, I have MacBook Pro... and then ? Commented Mar 13, 2017 at 22:45

1 Answer 1

2

According to your comment, your history object is undefined. Please try importing browserHistory instead of History and pass that into your router.

versions before React-Router v4 (Which I am assuming you are using since you are importing Router:

import { Router, Route, browserHistory } from 'react-router';

...

....
<Router history={browserHistory}>
  <Route path="/" component={App}>

React-Router v4:

Instead of importing Router/browserHistory, you import browserRouter, which is a router that creates it's own history instance. it would look like this:

import { BrowserRouter, Route } from 'react-router';
...

...

<BrowserRouter>
   <Route path="/" component={App}>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.