当前位置 : 主页 > 网页制作 > React >

reactjs – react路由器不呈现组件

来源:互联网 收集:自由互联 发布时间:2021-06-15
我用react-router开发我的项目. 下面是我的代码. const App2 = React.createClass({ render() { return ( div Link to="index"index/Link Link to="favorite"favorite/Link Link to="myPage"myPage/Link {this.props.children} /div ) }});var
我用react-router开发我的项目.

下面是我的代码.

const App2 = React.createClass({
    render() {
        return (
            <div>
                <Link to="index">index</Link>
                <Link to="favorite">favorite</Link>
                <Link to="myPage">myPage</Link>
                {this.props.children}
            </div>
        )
    }
});

var app = ReactDOM.render (
    <Router history={browserHistory}>
        <Route path="/" component={App2}>
            <Route path="index" component={PhotoFeedWrapper}/>
            <Route path="favorite" component={FavoriteWrapper}/>
            <Route path="myPage" component={MyPageWrapper}/>
        </Route>
    </Router>,
    document.getElementById('app')
);

我认为我的代码是正确的.但是,这会像下面一样呈空.

<div id="app"><!-- react-empty: 1 --></div>

没有脚本错误.

我做错了什么?

链接组件目前仅支持绝对路径.你必须改为:

<Link to="/index">index</Link>
<Link to="/favorite">favorite</Link>
<Link to="/myPage">myPage</Link>
网友评论