2016-11-25 145 views
0

給出能不能在這裏找到問題這可能是一個錯字,但我想我已經跟着文檔..陣營路由器不能正常工作時PARAMS

index.js:

ReactDOM.render(
    <Router history={hashHistory}> 
    <Route path="/" component={App}></Route> 
    <Route path="/match:id" component={MatchFeedComponent}></Route> 
    <Route path="/user" component={UserPageComponent}></Route> 
    <Route path="/comments" component={CommentHolderComponent}></Route> 
    <Route path="/post-talk" component={AddTalkComponent}></Route> 
    <Route path="/add-match" component={AddMatchComponent}></Route> 
    </Router>, 
    document.getElementById('app') 
); 

在我

<Link to={{ pathname:"/match/", query: {id: this.id}}}> 

我得到: [react-router] Location "/match/?id=-KXKIhpF8mdWDn9C5Tnd" did not match any routes

它工作正常,機智沒有任何參數,但現在找不到它。

回答

2

如果你想「ID」是查詢字符串PARAM,它不應該出現在你的路線。改成這樣:

<Route path="/match" component={MatchFeedComponent}></Route> 

...,然後就拿起你的組件內從props.location.query的ID

2

React路由器通常不適用於「常規查詢」,至少你如何設置它。您的路由器預計類似/match/-KXKIhpF8mdWDn9C5Tnd而不是/match/?id=-KXKIhpF8mdWDn9C5Tnd。試試這個作爲你的Link

<Link to={`/match/${this.id}`}> 

,然後改變你的路線:

<Route path="/match/:id" component={MatchFeedComponent}></Route>