TabRouter的Stack Navigator流问题

时间:2018-01-05 12:58:55

标签: react-native

Stack Navigator“Root” - 堆栈导航A.     - SN登录     - SN注册     - SN HOME 初始路线是“登录”

HOME包含标签导航 --Tab Navigator

--- TAB Navigator A

----屏幕“设置”

--- TAB Navigator B

----屏幕“1”

----屏幕“设置”

App.js

const AppNavigator = StackNavigator({
  Login: {
    screen: Login
  },
  SignUp: {
    screen: SignUp
  },
  TermsConditions: {
    screen: TermsConditions
  },
  Home: {
    screen: Home 
  },
    Setting: {
        screen: Setting
    }
}, {

  initialRouteName: "Login",
  headerMode: "none",
  // mode: 'modal',
  navigationOptions: {
    gesturesEnabled: false
  }
});

当用户登录时,导航到“主页”屏幕 - 结束打开卡车作为初始路线。 的 Home.js

const HomeNavigation = StackNavigator(
  {
    Home: {
      screen: Trucks
    },
    TruckDetailController: {
      screen: TruckDetailController
    },
    Setting: {
      screen: Setting
    },
  {
    initialRouteName: "Home",
    headerMode: "none"
  }
);

const FavouriteNavigation = StackNavigator(
  {
    Favourite: {
      screen: Favourite
    },
    TruckDetailController: {
      screen: TruckDetailController
    },
    Setting: {
      screen: Setting
    },
  {
    initialRouteName: "Favourite",
    headerMode: "none"
  }
);
const TabRoute = TabRouter(
  {
    Trucks: {
      screen: HomeNavigation
    },
    Favourite: {
      screen: FavouriteNavigation
    },
    Loyalty: {
      screen: Loyalty
    },
    Offer: {
      screen: Offer
    }
  },
  { initialRouteName: "Trucks" }
);

我只想从设置中退出并切换到“堆栈导航A - 登录”屏幕。

如果有人会给出上面的解决方案,那么它可以理解并提出一个好点。 :)

1 个答案:

答案 0 :(得分:1)

这里有两种选择。第一种方法是使用带有密钥的Back操作(当您在那里时,您必须保存Feed屏幕的密钥)。

第二种方法是使用Reset,但是你误解了actions数组的作用 - 它只用于为堆栈导航器构建堆栈。

要执行内部堆栈导航器导航,您必须在导航操作中指定一个操作:

const resetAction = NavigationActions.reset({
  index: 1,
  actions: [
    NavigationActions.navigate({
      routeName: '1',
      params: {},
      action: NavigationActions.navigate({
        routeName: 'Feed'
      })
    })
  ]
});