Reactjs 路由更改过程中的反应重发火灾行动
我正在使用“react router”:“^4.1.1”,并且我能够在我的项目中成功地使其工作。现在,当路由发生变化时,我需要启动并执行操作。我怎么做 /index.js/Reactjs 路由更改过程中的反应重发火灾行动,reactjs,redux,router,Reactjs,Redux,Router,我正在使用“react router”:“^4.1.1”,并且我能够在我的项目中成功地使其工作。现在,当路由发生变化时,我需要启动并执行操作。我怎么做 /index.js/ 渲染(( ), document.getElementById('root')) ) /Main.js/ 类主扩展React.Component{ render(){ 返回( ); } } 导出默认主; /组件/product.js/ constproduct=({ImageUrl,价格,数量,标题,ID})=>( {}
渲染((
),
document.getElementById('root'))
)
/Main.js/
类主扩展React.Component{
render(){
返回(
);
}
}
导出默认主;
/组件/product.js/
constproduct=({ImageUrl,价格,数量,标题,ID})=>(
{}
)
现在,我的reducer捕获了一个触发的操作,它负责填充数据。当路由发生时,如何启动操作?通常有两种方式: 1) 内部组件
import { browserHistory } from 'react-router';
//Your initialization
browserHistory.listen( location => {
//Do your stuff here
});
<Route path="/" onChange={yourHandler} component={AppContainer}>
<IndexRoute component={StaticContainer} />
<Route path="/a" component={ContainerA} />
<Route path="/b" component={ContainerB} />
</Route>
function yourHandler(previousRoute, nextRoute) {
//do your logic here
}
2) 在根组件中
import { browserHistory } from 'react-router';
//Your initialization
browserHistory.listen( location => {
//Do your stuff here
});
<Route path="/" onChange={yourHandler} component={AppContainer}>
<IndexRoute component={StaticContainer} />
<Route path="/a" component={ContainerA} />
<Route path="/b" component={ContainerB} />
</Route>
function yourHandler(previousRoute, nextRoute) {
//do your logic here
}
函数yourHandler(上一个路由,下一个路由){
//你的逻辑在这里吗
}
您还有其他问题吗?“当…”时,如何启动操作?您可以使用“渲染”或“子”路由方法,而不是“组件”。例如:{doSomething();return;}}/>你解决问题了吗?对不起,我在度假。那么根据你的回答,我的MAin.js会像这样吗?类Main扩展React.Component{{doSomething();return;}}}/>);导出默认主;谢谢,但“react router”:“^4.1.1”不再支持onChange
<Route path="/" onChange={yourHandler} component={AppContainer}>
<IndexRoute component={StaticContainer} />
<Route path="/a" component={ContainerA} />
<Route path="/b" component={ContainerB} />
</Route>
function yourHandler(previousRoute, nextRoute) {
//do your logic here
}