reactjs – 使用反应导航将导航历史记录重置为登录屏幕

前端之家收集整理的这篇文章主要介绍了reactjs – 使用反应导航将导航历史记录重置为登录屏幕前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在登录(欢迎)后用户导航到Home.我重置了历史记录,因此用户无法像这样返回:
const actionToDispatch = NavigationActions.reset({
            index: 0,actions: [NavigationActions.navigate({ routeName: 'Home' })]
        });

        this.props.navigation.dispatch(actionToDispatch);

这工作正常.按下注销后,用户应该返回欢迎,但它不起作用.这就是我在做什么:

const resetAction = NavigationActions.reset({
            index: 0,actions: [
                NavigationActions.navigate({ routeName: 'Welcome' }),]
        });

        this.props.navigation.dispatch(resetAction);

错误表示没有“欢迎”的路线.必须是“主要”,“隐私”,“条款”之一,它们是主页中某个标签的路线.见下文:

const AppStack = StackNavigator({
                    Welcome: {
                        screen: Welcome
                    },Home: {
                        screen: Tabs
                    }
                },{
                        initialRouteName: this.state.isLoggedIn ? 'Home' : 'Welcome',headerMode: 'none'
                    }
                );

export const ProfileStack = StackNavigator({
    Profile: {
        screen: Profile,},});

export const SettingsStack = StackNavigator({
    Settings: {
        screen: Settings,{
    });

export const InfoStack = StackNavigator({
    Main: {
        screen: Main,Privacy: {
        screen: Privacy
    },Terms: {
        screen: Terms
    }
});

const routeConfiguration = {

    Profile: { screen: ProfileStack },Settings: { screen: SettingsStack },Info: { screen: InfoStack }
};

const tabBarConfiguration = {
    tabBarOptions: {
        activeTintColor: 'white',inactiveTintColor: 'lightgray',labelStyle: {
            fontSize: Normalize(10),fontFamily: Fonts.book
        },style: {
            backgroundColor: Colors.greenLightGradient,borderTopWidth: 1,borderTopColor: Colors.tabGreenLine
        },}
};

export const Tabs = TabNavigator(routeConfiguration,tabBarConfiguration);
我在这里找到了解决方案: https://github.com/react-community/react-navigation/pull/789.
const resetAction = NavigationActions.reset({
            index: 0,],key: null
        });

this.props.navigation.dispatch(resetAction);

key:null是重要的部分.

原文链接:https://www.f2er.com/react/301268.html

猜你在找的React相关文章