最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - react-router: 'Invariant Violation: Invalid tag: {HelloWorld}', while the component is right there

programmeradmin2浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 16

If 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}.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论