React Navigation: Navigate Back To Root using NavigationActions.reset, goBack and getStateForAction

前端 未结 7 705
灰色年华
灰色年华 2020-12-28 15:05

Say I\'ve navigated through 4 screens in my StackNavigator App and now I want to go back to the first screen. There seems to be three different ways to do this and they do n

7条回答
  •  死守一世寂寞
    2020-12-28 16:01

    This is my working solution for reset back to home (root) without creating new route

    if(this.categoriesNav.state.nav.index >0){
        let k = this.categoriesNav.state.nav.routes[1].key;
        this.categoriesNav.dispatch(NavigationActions.back({key: k})); }
    

    categoriesNav is referenced to my stack navigator

提交回复
热议问题