我的应用程序正在使用 react v15 和 react-router 2.5.2. 配置很简单:
ReactDOM.render(
<Provider store={ store }>
<Router history={ browserHistory }>
<Route path="/" component={ App }>
<IndexRoute component={ Home } />
<Route path="incidents" component={ IncidentsContainer } />
<Route path="incident/:id" component={ IncidentContainer } />
<Route path="*" component={ NotFound } />
</Route>
</Router>
</Provider>
document.getElementById('dashboard')
);
只要导航发生在不同的路线上,一切正常,所以从incidents
到incident/:id
就没问题等等。如果我尝试从incident/1
导航到incident/2
,组件会更改 url,但路由事件永远不会被触发,所以实际上没有任何反应。这是创建链接但无法正常工作的组件。
handleClick() {
const { data } = this.props;
// This is called, the url changes but nothing happens
browserHistory.push('/incident/' + data.originIncidentId);
}
render() {
const { data } = this.props;
return (<span className="link" onClick={this.handleClick}>{data.originIncidentId}</span>);
}
知道为什么路由器不会为那个特定的 sub-route 开火,否则它会完美运行吗?谢谢。