【发布时间】:2017-08-19 14:07:14
【问题描述】:
您好,我正在尝试使用 navigate 函数导航到下一个组件。我正在使用react-navigation 在多个组件之间进行导航。
假设我有 index.android.js 和 DashboardScreen.js 组件。我正在尝试从索引组件导航到 DashboardScreen.js 组件。
它正在导航,但索引组件始终保留在组件堆栈中。当我按回然后它打开index.android.js 这不应该。有谁知道如何在react-native 管理这个。在 Android 中,finish() 适用于此。
navigate("DashboardScreen");
当我从SplashScreen 导航到EnableNotification 时,SplashScreen 应该被销毁,如果我从EnableNotification 导航到CreateMessage,那么EnableNotification 应该被销毁,如果我从@987654336 导航@ 到 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"
}
);
【问题讨论】:
标签: android react-native react-native-android react-navigation