2017-02-09 57 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 –

相關問題