0

我有一个这样的 StackNavigation:

const AppNavigator = createStackNavigator({

Login: {
    screen: Login,
    navigationOptions: () => ({
        title: 'Login',
        headerTintColor: 'white',
        headerStyle:{
            backgroundColor: '#000',
            elevation: 0,
            showdowOpacity: 0
        },
    })
},

Home: {
    screen: AppDrawerNavigator,
    navigationOptions: () => ({
        header: null
    })
},
});

使用嵌套在里面的 DrawerNavigator:

const AppDrawerNavigator = createDrawerNavigator({

Home: {
    screen: Home,
    navigationOptions: {
        drawerLabel: 'Home',
        gesturesEnabled: false,
    }
},

Favorites: {
    screen: Favorites,
    navigationOptions: {
        drawerLabel: 'Favorites',

    }
}

},
{
    drawerPosition: 'left',
    contentComponent: props => <Drawer {...props} />
});

堆栈导航器的初始路由工作正常

登录 -> 主页

但是当我尝试从主页导航到收藏夹时,它会在呈现收藏夹屏幕后立即导航回主页。

我正在使用 react-navigation@2.11.2 和 react-native@0.56.0

4

1 回答 1

1

在堆栈和抽屉导航器中都使用 Home。这里发生名称冲突的可能性很高。

试试这个结构。

const Stack = {
    FirstView: {
        screen: FirstView
    },
    SecondView: {
        screen: SecondView
    },
    ThirdView: {
        screen: ThirdView
    }
};

const DrawerRoutes = {
    FirstViewStack: {
        name: 'FirstViewStack',
        screen: StackNavigator(Stack, { initialRouteName: 'FirstView' })
    },
    SecondViewStack: {
        name: 'SecondViewStack',
        screen: StackNavigator(Stack, { initialRouteName: 'SecondView' })
    },
    ThirdViewStack: {
        name: 'ThirdViewStack',
        screen: StackNavigator(Stack, { initialRouteName: 'ThirdView' })
    },
};

const RootNavigator =
    StackNavigator({
        Drawer: {
            name: 'Drawer',
            screen: DrawerNavigator(
                DrawerRoutes,
            ),
        },
        ...Stack
    },
        {
            headerMode: 'none'
        }
    );

当我尝试在主页中使用汉堡菜单(使用堆栈导航器转到其他页面)时,我遇到了类似的问题。

也检查这篇Git 文章

于 2018-11-21T08:54:04.360 回答