React-router history : Uncaught TypeError: Cannot read property 'location' of undefined
I'm trying to make an old React app run and I keep getting this error:
Uncaught TypeError: Cannot read property 'location' of undefined
at new Router (main.js:1903)
at ReactCompositeComponentWrapper.mountComponent (main.js:9251)
at Object.mountComponent (main.js:16713)
at ReactCompositeComponentWrapper.mountComponent (main.js:9323)
at Object.mountComponent (main.js:16713)
at mountComponentIntoNode (main.js:14601)
at ReactReconcileTransaction.perform (main.js:19365)
at batchedMountComponentIntoNode (main.js:14617)
at ReactDefaultBatchingStrategyTransaction.perform (main.js:19365)
at Object.batchedUpdates (main.js:12197)
I've tried installing different versions of react-router and history but I still keep getting the same error, the code looks fine so I'm not sure where the issue could be.
This is my 'package.json':
{
"name": "react-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "watchify src/main.jsx -v -t [ babelify --presets [ react ] ] -o public/js/main.js",
"test": "echo "Error: no test specified" && exit 1"
},
"repository": {
"type": "",
"url": ""
},
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": "",
"dependencies": {
"babel-preset-react": "^6.1.18",
"babelify": "^7.2.0",
"history": "^1.13.1",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-router": "^1.0.2",
"watchify": "^3.6.1"
}
}
This was written in react version 0.14.3 with react-router & history version 1.
Main.jsx
let React = require('react');
let ReactDOM = require('react-dom');
let Routes = require('./Routes.jsx');
ReactDOM.render(Routes, document.getElementById('main'));
Below I have some nested routes, the problem seems to be when it tries to resolve this.props.children
on the Base.jsx component based on the routes here in:
Routes.jsx
let React = require('react');
let ReactRouter = require('react-router');
let Router = ReactRouter.Router;
let Route = ReactRouter.Route;
let Base = require('./components/Base.jsx');
let Page1 = require('./components/Page1.jsx');
let Page2 = require('./components/Page2.jsx');
let Routes = (
<Router>
<Route path="/" component={Base}>
<Route path="/page1" component={Page1} />
<Route path="/page2" component={Page2} />
</Route>
</Router>
);
module.exports = Routes;
Below, not sure if the issue lies on the resolution of this.props.children
Base.jsx
let React = require('react');
let Base = React.createClass({
render: function(){
return(
<div>
<h1>Header</h1>
{this.props.children}
<h1>Footer</h1>
</div>
);
}
});
module.exports = Base;
Page1.jsx
let React = require('react');
let Page1 = React.createClass({
render: function(){
return(
<h1>Page 1</h1>
);
}
});
module.exports = Page1;
Page2.jsx
let React = require('react');
let Page2 = React.createClass({
render: function(){
return(
<h1>Page 2</h1>
);
}
});
module.exports = Page2;
index.html
<!DOCTYPE html>
<html>
<head>
<title>React Routing</title>
</head>
<body>
<div id="main">
</div>
<script src="js/main.js"></script>
</body>
</html>
Any help will be greatly appreciated, I'm new to React and I can't get this thing to run.
javascript reactjs react-router history.js
add a comment |
I'm trying to make an old React app run and I keep getting this error:
Uncaught TypeError: Cannot read property 'location' of undefined
at new Router (main.js:1903)
at ReactCompositeComponentWrapper.mountComponent (main.js:9251)
at Object.mountComponent (main.js:16713)
at ReactCompositeComponentWrapper.mountComponent (main.js:9323)
at Object.mountComponent (main.js:16713)
at mountComponentIntoNode (main.js:14601)
at ReactReconcileTransaction.perform (main.js:19365)
at batchedMountComponentIntoNode (main.js:14617)
at ReactDefaultBatchingStrategyTransaction.perform (main.js:19365)
at Object.batchedUpdates (main.js:12197)
I've tried installing different versions of react-router and history but I still keep getting the same error, the code looks fine so I'm not sure where the issue could be.
This is my 'package.json':
{
"name": "react-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "watchify src/main.jsx -v -t [ babelify --presets [ react ] ] -o public/js/main.js",
"test": "echo "Error: no test specified" && exit 1"
},
"repository": {
"type": "",
"url": ""
},
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": "",
"dependencies": {
"babel-preset-react": "^6.1.18",
"babelify": "^7.2.0",
"history": "^1.13.1",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-router": "^1.0.2",
"watchify": "^3.6.1"
}
}
This was written in react version 0.14.3 with react-router & history version 1.
Main.jsx
let React = require('react');
let ReactDOM = require('react-dom');
let Routes = require('./Routes.jsx');
ReactDOM.render(Routes, document.getElementById('main'));
Below I have some nested routes, the problem seems to be when it tries to resolve this.props.children
on the Base.jsx component based on the routes here in:
Routes.jsx
let React = require('react');
let ReactRouter = require('react-router');
let Router = ReactRouter.Router;
let Route = ReactRouter.Route;
let Base = require('./components/Base.jsx');
let Page1 = require('./components/Page1.jsx');
let Page2 = require('./components/Page2.jsx');
let Routes = (
<Router>
<Route path="/" component={Base}>
<Route path="/page1" component={Page1} />
<Route path="/page2" component={Page2} />
</Route>
</Router>
);
module.exports = Routes;
Below, not sure if the issue lies on the resolution of this.props.children
Base.jsx
let React = require('react');
let Base = React.createClass({
render: function(){
return(
<div>
<h1>Header</h1>
{this.props.children}
<h1>Footer</h1>
</div>
);
}
});
module.exports = Base;
Page1.jsx
let React = require('react');
let Page1 = React.createClass({
render: function(){
return(
<h1>Page 1</h1>
);
}
});
module.exports = Page1;
Page2.jsx
let React = require('react');
let Page2 = React.createClass({
render: function(){
return(
<h1>Page 2</h1>
);
}
});
module.exports = Page2;
index.html
<!DOCTYPE html>
<html>
<head>
<title>React Routing</title>
</head>
<body>
<div id="main">
</div>
<script src="js/main.js"></script>
</body>
</html>
Any help will be greatly appreciated, I'm new to React and I can't get this thing to run.
javascript reactjs react-router history.js
add a comment |
I'm trying to make an old React app run and I keep getting this error:
Uncaught TypeError: Cannot read property 'location' of undefined
at new Router (main.js:1903)
at ReactCompositeComponentWrapper.mountComponent (main.js:9251)
at Object.mountComponent (main.js:16713)
at ReactCompositeComponentWrapper.mountComponent (main.js:9323)
at Object.mountComponent (main.js:16713)
at mountComponentIntoNode (main.js:14601)
at ReactReconcileTransaction.perform (main.js:19365)
at batchedMountComponentIntoNode (main.js:14617)
at ReactDefaultBatchingStrategyTransaction.perform (main.js:19365)
at Object.batchedUpdates (main.js:12197)
I've tried installing different versions of react-router and history but I still keep getting the same error, the code looks fine so I'm not sure where the issue could be.
This is my 'package.json':
{
"name": "react-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "watchify src/main.jsx -v -t [ babelify --presets [ react ] ] -o public/js/main.js",
"test": "echo "Error: no test specified" && exit 1"
},
"repository": {
"type": "",
"url": ""
},
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": "",
"dependencies": {
"babel-preset-react": "^6.1.18",
"babelify": "^7.2.0",
"history": "^1.13.1",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-router": "^1.0.2",
"watchify": "^3.6.1"
}
}
This was written in react version 0.14.3 with react-router & history version 1.
Main.jsx
let React = require('react');
let ReactDOM = require('react-dom');
let Routes = require('./Routes.jsx');
ReactDOM.render(Routes, document.getElementById('main'));
Below I have some nested routes, the problem seems to be when it tries to resolve this.props.children
on the Base.jsx component based on the routes here in:
Routes.jsx
let React = require('react');
let ReactRouter = require('react-router');
let Router = ReactRouter.Router;
let Route = ReactRouter.Route;
let Base = require('./components/Base.jsx');
let Page1 = require('./components/Page1.jsx');
let Page2 = require('./components/Page2.jsx');
let Routes = (
<Router>
<Route path="/" component={Base}>
<Route path="/page1" component={Page1} />
<Route path="/page2" component={Page2} />
</Route>
</Router>
);
module.exports = Routes;
Below, not sure if the issue lies on the resolution of this.props.children
Base.jsx
let React = require('react');
let Base = React.createClass({
render: function(){
return(
<div>
<h1>Header</h1>
{this.props.children}
<h1>Footer</h1>
</div>
);
}
});
module.exports = Base;
Page1.jsx
let React = require('react');
let Page1 = React.createClass({
render: function(){
return(
<h1>Page 1</h1>
);
}
});
module.exports = Page1;
Page2.jsx
let React = require('react');
let Page2 = React.createClass({
render: function(){
return(
<h1>Page 2</h1>
);
}
});
module.exports = Page2;
index.html
<!DOCTYPE html>
<html>
<head>
<title>React Routing</title>
</head>
<body>
<div id="main">
</div>
<script src="js/main.js"></script>
</body>
</html>
Any help will be greatly appreciated, I'm new to React and I can't get this thing to run.
javascript reactjs react-router history.js
I'm trying to make an old React app run and I keep getting this error:
Uncaught TypeError: Cannot read property 'location' of undefined
at new Router (main.js:1903)
at ReactCompositeComponentWrapper.mountComponent (main.js:9251)
at Object.mountComponent (main.js:16713)
at ReactCompositeComponentWrapper.mountComponent (main.js:9323)
at Object.mountComponent (main.js:16713)
at mountComponentIntoNode (main.js:14601)
at ReactReconcileTransaction.perform (main.js:19365)
at batchedMountComponentIntoNode (main.js:14617)
at ReactDefaultBatchingStrategyTransaction.perform (main.js:19365)
at Object.batchedUpdates (main.js:12197)
I've tried installing different versions of react-router and history but I still keep getting the same error, the code looks fine so I'm not sure where the issue could be.
This is my 'package.json':
{
"name": "react-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "watchify src/main.jsx -v -t [ babelify --presets [ react ] ] -o public/js/main.js",
"test": "echo "Error: no test specified" && exit 1"
},
"repository": {
"type": "",
"url": ""
},
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": "",
"dependencies": {
"babel-preset-react": "^6.1.18",
"babelify": "^7.2.0",
"history": "^1.13.1",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-router": "^1.0.2",
"watchify": "^3.6.1"
}
}
This was written in react version 0.14.3 with react-router & history version 1.
Main.jsx
let React = require('react');
let ReactDOM = require('react-dom');
let Routes = require('./Routes.jsx');
ReactDOM.render(Routes, document.getElementById('main'));
Below I have some nested routes, the problem seems to be when it tries to resolve this.props.children
on the Base.jsx component based on the routes here in:
Routes.jsx
let React = require('react');
let ReactRouter = require('react-router');
let Router = ReactRouter.Router;
let Route = ReactRouter.Route;
let Base = require('./components/Base.jsx');
let Page1 = require('./components/Page1.jsx');
let Page2 = require('./components/Page2.jsx');
let Routes = (
<Router>
<Route path="/" component={Base}>
<Route path="/page1" component={Page1} />
<Route path="/page2" component={Page2} />
</Route>
</Router>
);
module.exports = Routes;
Below, not sure if the issue lies on the resolution of this.props.children
Base.jsx
let React = require('react');
let Base = React.createClass({
render: function(){
return(
<div>
<h1>Header</h1>
{this.props.children}
<h1>Footer</h1>
</div>
);
}
});
module.exports = Base;
Page1.jsx
let React = require('react');
let Page1 = React.createClass({
render: function(){
return(
<h1>Page 1</h1>
);
}
});
module.exports = Page1;
Page2.jsx
let React = require('react');
let Page2 = React.createClass({
render: function(){
return(
<h1>Page 2</h1>
);
}
});
module.exports = Page2;
index.html
<!DOCTYPE html>
<html>
<head>
<title>React Routing</title>
</head>
<body>
<div id="main">
</div>
<script src="js/main.js"></script>
</body>
</html>
Any help will be greatly appreciated, I'm new to React and I can't get this thing to run.
javascript reactjs react-router history.js
javascript reactjs react-router history.js
asked Nov 25 '18 at 4:34
Jose VasconcellosJose Vasconcellos
15
15
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464680%2freact-router-history-uncaught-typeerror-cannot-read-property-location-of-un%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464680%2freact-router-history-uncaught-typeerror-cannot-read-property-location-of-un%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown