Chapter 13 of Learning React Problem with React Router

My code works perfectly fine with this code.

ReactDOM.render(
<div>
   <App/>
</div>,
destination
);

However when I proceed to set up the React Router.

ReactDOM.render(
  <ReactRouter.Router>
        <ReactRouter.Route path ="/" component={App}>

        </ReactRouter.Route>
  <ReactRouter.Router>,
destination
);

Once I load the document in Google Chrome. Dev Tools gives me the following error.

Uncaught TypeError: Cannot read property ‘getCurrentLocation’ of undefined
at Constructor.createTransitionManager (ReactRouter.min.js:1)
at Constructor.componentWillMount (ReactRouter.min.js:1)
at react.js:6244
at measureLifeCyclePerf (react.js:5971)
at ReactCompositeComponentWrapper.performInitialMount (react.js:6243)
at ReactCompositeComponentWrapper.mountComponent (react.js:6154)
at Object.mountComponent (react.js:13768)
at ReactCompositeComponentWrapper.performInitialMount (react.js:6267)
at ReactCompositeComponentWrapper.mountComponent (react.js:6154)
at Object.mountComponent (react.js:13768)

1 Like

Does your full code look like the following:

<!DOCTYPE html>
<html>
<head>
  <title>React Test</title>
  <script src="https://unpkg.com/[email protected]/dist/react.js"></script>
  <script src="https://unpkg.com/[email protected]/dist/react-dom.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
  <script src="https://npmcdn.com/[email protected]/umd/ReactRouter.min.js"></script>

  <style>

  </style>
</head>

<body>
  <div id="container"></div>

<script type="text/babel">
  var destination = document.querySelector("#container");

  var App = React.createClass({
    render: function() {
      return (
        <div>
          <h1>Simple SPA</h1>
          <ul className="header">
            <li>Home</li>
            <li>Stuff</li>
            <li>Contact</li>
          </ul>
          <div className="content">

          </div>
        </div>
      )
    }
  });

  ReactDOM.render(
    <ReactRouter.Router>
      <ReactRouter.Route path="/" component={App}>

      </ReactRouter.Route>
    </ReactRouter.Router>,
    destination
  );
</script>
</body>

</html>

I am at the exact step you are, and I don’t see the error that you are seeing.

Thank you; The print edition of your book doesn’t include “[email protected]/” it was simply
"react-router"

Yikes! That is a bug that needs to be fixed.

It works to change that react-router however I get this error code:

react.js:20478 Warning: You are manually calling a React.PropTypes validation function for the component prop on Route. This is deprecated and will not work in the next major version. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details.
printWarning @ react.js:20478
react.js:20478 Warning: You are manually calling a React.PropTypes validation function for the components prop on Route. This is deprecated and will not work in the next major version. You may be seeing this warning due to a third-party PropTypes library.
printWarning @ react.js:20478
react.js:20478 Warning: You are manually calling a React.PropTypes validation function for the getComponent prop on Route. This is deprecated and will not work in the next major version. You may be seeing this warning due to a third-party PropTypes library.
printWarning @ react.js:20478
react.js:20478 Warning: You are manually calling a React.PropTypes validation function for the getComponents prop on Route. This is deprecated and will not work in the next major version. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details.

The version or React Router the book talks about has been replaced by a newer version. That’s why you are seeing these warnings. The warnings are OK for now, but you will need to update to a newer version of the Router. I haven’t had a chance to update it yet either, but I’ll do so and post an updated tutorial shortly :slight_smile:

1 Like

I tried the your very code(copy & past) in my visual studio code and still it didn’t work.

Can you post your full source code?