2016-11-25 148 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>