2017-02-09 59 views
0

下面是我的路由代码。我能够从displaylist路由到informationlist和信息列表我从数据库中获取所有数据,但是我想根据他们的Id或其他显示一个学生显示数据。我现在应该怎么做? 每次我需要显示不同的学生的详细信息。如何从数据库中的对象数组中路由和显示特定的对象?

这是我的路由器。

<Router history={hashHistory}> 
    <Route path="/" component={App}/> 
    <Route path="/students" component={Students}/> 
    <Route path="/holidays" component={Calender}/> 
    <Route path="/premontessori" component={Premontessori}/> 
    <Route path="/createstudent" component={Createstudent}/> 
    <Route path="/montessori1" component={Montessori1}/> 
    <Route path="/montessori2" component={Montessori2}/> 
    <Route path="/displaylist" component={Displaylist}/> 
    <Route path="/information" component={Information}/> 
    </Router>, document.getElementById('app')); 

这是从显示列表我的链接informationlist

<Link to="/information" style={{textDecoration:'none'}} > 

回答

0

一个超级幼稚的做法看起来有点像这个

<Route path="/students/:id/" component={Student} /> 

const Student = React.createClass({ 
    componentDidMount: function() { 
     var id = this.props.params.id; 
     return MyAPIClient.get('/path-to-my-api/?studentId=' + id).then(function (data) { this.setState({student: data }.bind(this)); 
    }, 
    render: function() { 
     // Render your HTML 
    } 
}); 
+0

你能给我一些链接的文档,这样我可以去通过它详细 –

+0

这里雅'去https://github.com/ReactTraining/react-router/blob/master/docs/guides/ComponentLifecycle.md#fetching-data –

相关问题