您好,我正在尝试使用 navigate
函数导航到下一个组件。我正在使用 react-navigation
在多个组件之间导航。
假设我有 index.android.js
和 DashboardScreen.js
组件。我正在尝试从索引组件导航到 DashboardScreen.js
组件。
它正在导航,但索引组件始终保留在组件堆栈中。当我按回去时,它会打开 index.android.js
,这不应该。有谁知道如何在 react-native
中管理它。在 Android 中,finish()
适用于此。
navigate("DashboardScreen");
当我从 SplashScreen
导航到 EnableNotification
时,如果我从 EnableNotification
导航,那么 SplashScreen
应该被销毁> 到 CreateMessage
然后 EnableNotification
应该被销毁,如果我从 CreateMessage
导航到 DashboardScreen
然后 CreateMessage
应该被销毁。截至目前,没有任何组件被销毁。
index.android.js
class SplashScreen extends Component {
render() {
if (__DEV__) {
console.disableYellowBox = true;
}
const { navigate } = this.props.navigation;
AsyncStorage.getItem("@ProductTour:key").then(value => {
console.log(value);
if (value) {
navigate("DashboardScreen");
}
});
return (
....
);
}
}
const App = StackNavigator(
{
Splash: {
screen: SplashScreen,
navigationOptions: {
header: {
visible: false
}
}
},
EnableNotification: {
screen: EnableNotificationScreen,
navigationOptions: {
header: {
visible: false
}
}
},
CreateMessage: {
screen: CreateMessageScreen,
navigationOptions: {
header: {
visible: false
}
}
},
DashboardScreen: {
screen: DashboardScreen,
navigationOptions: {
header: {
visible: false
}
}
}
},
{
initialRouteName: "Splash"
}
);
最佳答案
只需使用“replace”代替“navigate”
this.props.navigation.replace('Your Next Component Name')
关于android - 如何在导航到 React Native 中的下一个组件时完成当前组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45772523/