owais
owais

Reputation: 4922

React create element type invalid after including router

When I have added react router it gives me follow errors enter image description here

here is main.js

var React = require('react');
var ReactDOM = require('react-dom');
var Router = require('react-router');
var Route = require('react-router').Route;
var Home = require("./components/homePage");
ReactDOM.render(
    <Router >
        <Route component={Home} path="/"></Route>
    </Router>
    , document.getElementById('app'));

Homepage.js

var React = require('react');
var Home = React.createClass({
    render: function(){
        return (
            <div >
                <h1>Home</h1>
            </div>
        );
    }
});

module.exports = Home;

There are many others questions related to same problem but none of them address the real issue or general reason or cause. other answers suggesting using react-router 4 alpha and i have tried beta4 but still same error

Upvotes: 1

Views: 115

Answers (2)

rgommezz
rgommezz

Reputation: 13916

You are importing React Router components wrongly, it should be:

var Router = require('react-router').Router

var Route = require('react-router').Route

Upvotes: 3

prosti
prosti

Reputation: 46331

There was a similar question like yours, but tricky you cannot say it is a duplicate, at least the error is the same.

Based on the ES5 syntax you are using I guess your example is old. Try using the different version of the React Router.

Or just start with some new ES6 syntax React Router example.

Upvotes: 1

Related Questions