I'm new to React and am trying to get up to speed with react-router (v1.0.0).
I've setup a simple ponent and a simple route, but it's giving me an error: Invariant Violation: Invalid tag: {HelloWorld}
. You'd think it to be a clear error, but I can't figure out what's wrong with the code.
Here it is:
var HelloWorld = React.createClass({
render: function() {
return (
<p>Hello world</p>
);
}
});
var routes = (
<Router>
<Route path="/" ponent="{HelloWorld}"/>
</Router>
);
ReactDom.render(routes, document.querySelector('#main'));
If I switch out routes
with <HelloWorld />
in the ReactDom.render
statement, it works fine.
Any help is much appreciated!
I'm new to React and am trying to get up to speed with react-router (v1.0.0).
I've setup a simple ponent and a simple route, but it's giving me an error: Invariant Violation: Invalid tag: {HelloWorld}
. You'd think it to be a clear error, but I can't figure out what's wrong with the code.
Here it is:
var HelloWorld = React.createClass({
render: function() {
return (
<p>Hello world</p>
);
}
});
var routes = (
<Router>
<Route path="/" ponent="{HelloWorld}"/>
</Router>
);
ReactDom.render(routes, document.querySelector('#main'));
If I switch out routes
with <HelloWorld />
in the ReactDom.render
statement, it works fine.
Any help is much appreciated!
Share Improve this question asked Nov 15, 2015 at 9:19 MeldonMeldon 8502 gold badges7 silver badges13 bronze badges1 Answer
Reset to default 16If you look at the documentation again, you will see that ponent
expects a reference to a ponent, not a string:
ponent={HelloWorld}
// ^ ^
In JSX attribute values, "..."
represents a string (just like in JavaScript), and {...}
represents an arbitrary JavaScript expression. Hence "{HelloWorld}"
is very different from {HelloWorld}
.