我在我的 react native 项目中使用以下导航设置。在这里,我使用抽屉导航和堆栈导航。
import MainScreen from '../components/MainScreen';
import SettingsScreen from '../components/SettingsScreen';
import FriendsListScreen from '../components/FriendsListScreen';
import FriendProfileScreen from '../components/FriendProfileScreen';
// stack navigator - 1
const MainScreenStack = createStackNavigator(
{
MainScreen: MainScreen,
FriendsListScreen: FriendsListScreen,
FriendProfileScreen: FriendProfileScreen,
},
{
initialRouteName: 'MainScreen',
navigationOptions: {
drawerLabel: "Home"
},
}
);
// stack navigator - 2
const SettingsScreenStack = createStackNavigator(
{
SettingsScreen: SettingsScreen
},
{
navigationOptions: {
drawerLabel: "Settings"
},
}
);
// drawer navigation (stack navigator 1 + 2)
const AppNavigator = DrawerNavigator({
MainScreen: MainScreenStack,
SettingsScreen: SettingsScreenStack
});
const AppContainer = createAppContainer(AppNavigator)
设想:
- 从抽屉中,我单击“主页”链接并导航到 MainScreen。
- 从 MainScreen,我单击一个按钮并导航到 FriendsListScreen。
- 在 FriendsListScreen 中,我再次打开抽屉并单击“主页”链接。抽屉关闭,没有导航发生。
小样:
当我从抽屉中单击“主页”链接时,有没有办法导航回主屏幕?