【发布时间】:2017-07-21 07:00:33
【问题描述】:
我正在使用具有如下路由结构的 react-router:
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 变化时,组件应该卸载,但似乎我可能错过了一些东西。我应该如何解决这个问题?
非常感谢任何帮助!
【问题讨论】:
标签: javascript reactjs meteor react-router