以多个方式反应App

时间:2017-09-06 13:06:10

标签: reactjs router multipage

我尝试做一个反应应用程序,我想在我点击一个链接时做第二页,但当我点击该组件出现在链接下方而不是在另一页面中。我不明白为什么?

render() {
    return (
<Router>
        <div id="tableau">

          <Table compact celled >
              <Table.Body>
                <Table.Row>
                  <Link to="/sub"><Table.Cell onClick={this.test.bind(this)}>{this.props.topic.text}</Table.Cell>
                  <Table.Cell>{this.props.topic.arn}</Table.Cell></Link>
                    <Table.Cell collapsing>
                      <Button circular onClick={this.handleOpenModal}>S'inscrire</Button>
                        <ReactModal isOpen={this.state.showModal} contentLabel="Minimal Modal Example">

                            <button onClick={this.handleCloseModal}>Close Modal</button>
                            <AppInscription></AppInscription>

                        </ReactModal>
                        <Link to="/"><Button  circular >Cacher</Button></Link>
                      <Button circular  onClick={this.deleteThisTopic.bind(this)}>Suprimer</Button>
                    </Table.Cell>
                </Table.Row>
              </Table.Body>
             </Table>
             <Route exact path="/sub" component={AppSub}/>

           </div>
</Router>

1 个答案:

答案 0 :(得分:1)

您需要将上半部分包裹在路线中。路径用作匹配的模式,并确定应显示的内容。

render() {
    return (
        <Router>
            <div id="tableau">
                <Route exact path='/' render={() => (
                    <Table compact celled >
                        <Table.Body>
                            <Table.Row>
                            <Link to="/sub"><Table.Cell onClick={this.test.bind(this)}>{this.props.topic.text}</Table.Cell>
                            <Table.Cell>{this.props.topic.arn}</Table.Cell></Link>
                                <Table.Cell collapsing>
                                <Button circular onClick={this.handleOpenModal}>S'inscrire</Button>
                                    <ReactModal isOpen={this.state.showModal} contentLabel="Minimal Modal Example">

                                        <button onClick={this.handleCloseModal}>Close Modal</button>
                                        <AppInscription></AppInscription>

                                    </ReactModal>
                                    <Link to="/"><Button  circular >Cacher</Button></Link>
                                <Button circular  onClick={this.deleteThisTopic.bind(this)}>Suprimer</Button>
                                </Table.Cell>
                            </Table.Row>
                        </Table.Body>
                    </Table>
                )} />
                <Route exact path="/sub" component={AppSub}/>
            </div>
        </Router> 
    )
}