react-navigation跨tab路由处理
一般应用都有跨tab跳转的需求,这就需要特别处理下路由. 下面是使用 具体情境是: app分三大模块 首先选择路由结构,选择使用最外层是 const Components = { HomeTwo: { screen: HomeTwo,path:'app/HomeTwo' },HomeThree: { screen: HomeThree,path:'app/HomeThree' },BillTwo: { screen: BillTwo,path:'app/BillTwo' },BillThree: { screen: BillThree,path:'app/BillThree' },} const Tabs = TabNavigator({ Home: { screen: Home,path:'app/home',navigationOptions: { tabBar: { label: '首页',icon: ({tintColor}) => (<Image source={require('./images/home.png')} style={[{tintColor: tintColor},styles.icon]}/>),},} },Bill: { screen: Bill,path:'app/bill',navigationOptions: { tabBar: { label: '账单',icon: ({tintColor}) => (<Image source={require('./images/bill.png')} style={[{tintColor: tintColor},Me: { screen: Me,path:'app/me',navigationOptions: { tabBar: { label: '我',icon: ({tintColor}) => (<Image source={require('./images/me.png')} style={[{tintColor: tintColor},} } },{ tabBarPosition: 'bottom',swipeEnabled: false,animationEnabled: false,lazyLoad: false,backBehavior: 'none',tabBarOptions: { activeTintColor: '#ff8500',inactiveTintColor: '#999',showIcon: true,indicatorStyle: { height: 0 },style: { backgroundColor: '#fff',labelStyle: { fontSize: 10,}); const Navs = StackNavigator({ Home: { screen: Tabs,path:'app/Home' },Bill: { screen: Tabs,path:'app/Bill' },Me: { screen: Tabs,path:'app/Me' },...Components },{ initialRouteName: 'Home',navigationOptions: { header: { style: { backgroundColor: '#fff' },titleStyle: { color: 'green' } },cardStack: { gesturesEnabled: true } },mode: 'card',headerMode: 'screen' }); 在 // push BillTwo this.props.navigation.dispatch(resetAction); // 使用reset action重置路由 const resetAction = NavigationActions.reset({ index: 1,// 注意不要越界 actions: [ // 栈里的路由信息会从 Home->HomeTwo 变成了 Bill->BillTwo NavigationActions.navigate({ routeName: 'Bill'}),NavigationActions.navigate({ routeName: 'BillTwo'}) ] }); 从 http://www.bijishequ.com/detail/369321 react-navigation自带的 React-navigation作为路由组件的一种方式.http://www.bijishequ.com/detail/369321 Bill账单首页. TabNavigator和其他组件. reset action就可以重置路由信息了:Bill账单首页了. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |