react-router:导航到URL工作,但pushState抱怨“不匹配任何路由”

时间:2015-12-06 01:11:57

标签: reactjs react-router

当我执行以下操作时:

routeToCreateCreatives() {
  this.props.pushState(null, 'create');
}

它改变了网址:     http://localhost:3000/campaign/SLUG/creatives/create

但是我收到了这个警告:

Warning: Location "creatives/create" did not match any routes

奇怪的是,当我刷新页面或导航到URL时,它会加载。

以下是我的嵌套路线:

<Route path="/campaign/:campaignId" component={Campaign}>
  <IndexRoute component={CampaignDashboard} />
  <Route path="dashboard" component={CampaignDashboard}/>
  <Route path="creatives" component={Creatives}/>
  <Route path="creatives/create" component={CreativesCreate}/>
</Route>

最后,如果我使用如下所示的绝对路径,则链接有效。使用pushState时遇到一些问题:campaignId slug。

pushState(null, `/campaign/${campaign.id}/creatives`);

0 个答案:

没有答案