1.修改createBottomtabNavigator.js 中 _renderTabBar()方法的代码,在:const options = descriptor.options; 后添加代码,如下:
```const params = route.routes[route.index]['params'];```
/*添加选择的索引*/
if (params &&"selectIndex" in params){
const route1 = state.routes[params.selectIndex];
navigation.dispatch(navigation.navigate({
routeName: route1.routeName
}));
//恢复原来选项的索引,不然无法切换回原来页面
params.selectIndex=params.oriSelectIndex;
}
2.使用:在需要设置选择某一个tabItem的事件中实现如下代码:
const navigation =this.props.navigation;
navigation.setParams({selectIndex:0,oriSelectIndex:2});