Javascript 反应导航:检测应用程序导航到哪个屏幕
我有两个部分:Javascript 反应导航:检测应用程序导航到哪个屏幕,javascript,reactjs,react-native,react-navigation,react-props,Javascript,Reactjs,React Native,React Navigation,React Props,我有两个部分: 仪表板-应用程序的入口点 职位 在仪表板中,componentDidMount中有一个API调用。 在Posts组件中,收到帖子后,我导航到Dashboard。是否可以检测应用程序是否从POST导航到仪表板,并删除componentDidMount中的API调用 检查以下代码: // Dashboard.js componentDidMount() { this.handleApiCall(); // default axios get request // Here
// Dashboard.js
componentDidMount() {
this.handleApiCall(); // default axios get request
// Here I need to detect if the user was navigated to Dashboard from Posts or other component
}
// Posts.js
handleNavigation = () => {
this.setState({
isOpen: false,
});
this.props.navigation.navigate('Dashboard');
};
谢谢 尝试从
Posts.js
// Dashboard.js
componentDidMount() {
const { navigation } = this.props;
const fromPosts = navigation.getParam('fromPosts', false);
if(!fromPosts) {
this.handleApiCall(); // default axios get request
}
}
// Posts.js
handleNavigation = () => {
this.setState({
isOpen: false,
});
this.props.navigation.navigate('Dashboard', {fromPosts: true});
};
也许您可以从
posts.js
传递参数this.props.navigation.navigate('RouteName',{fromPosts:true})