我使用的反应 - 路由器的路由结构,像这样:反应路由器:调用componentWillUnmount在不同的非嵌套路线
const routes = (
<Router history={browserHistory}>
<Route path="/main" component={MainPage}></Route>
<Route path="/charts/:chartID" component={App}></Route>
</Router>
)
我试图做一个呼叫流星方法,当用户切换远离“/ charts /:chartID”到“/ main”。我只想被调用一次,如果可能的
在App.js的方法,我用生命周期方法:
componentDidUpdate(){
Meteor.call('test',"update");
} // prints "update"
componentWillUnmount(){
Meteor.call('test',"unmount");
} // nothing happens when url changes
Main.js(服务器):
Meteor.methods({
'test'(obj){
console.log(obj)
}
})
我读从这个source组件应该卸载时,在我的情况下,URL的变化,但似乎我可能错过了一些东西。我应该如何解决这个问题?
任何帮助,非常感谢!