加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – react路由器不呈现组件

发布时间:2020-12-15 09:35:20 所属栏目:百科 来源:网络整理
导读:我用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 = ReactDO
我用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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读