react-navigation跨tab路由处理
来源:互联网 发布:化学结构 数据可视化 编辑:程序博客网 时间:2024/06/15 15:37
一般应用都有跨tab跳转的需求, 这就需要特别处理下路由. 下面是使用React-navigation
作为路由组件的一种方式.http://www.bijishequ.com/detail/369321
具体情境是: app分三大模块Home
主页, Bill
账单和Me
我的, 对应三个tab. 现在需求是 Home
push HomeTwo
, HomeTwo
push BillTwo
, BillTwo
返回到 Bill
账单首页.
首先选择路由结构, 选择使用最外层是StackNavigator
, 然后包含3个TabNavigator
和其他组件.
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},styles.icon]}/>), }, } }, Me: { screen: Me, path:'app/me', navigationOptions: { tabBar: { label: '我', icon: ({tintColor}) => (<Image source={require('./images/me.png')} style={[{tintColor: tintColor},styles.icon]}/>), }, } } }, { 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' });
在HomeTwo
里使用react-navigation
自带的reset action
就可以重置路由信息了:
// push BillTwothis.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'}) ]});
从HomeTwo
push 到 BillTwo
页面后, 点击BillTwo
的左上角导航按钮返回就能返回到Bill
账单首页了.
http://www.bijishequ.com/detail/369321
具体情境是: app分三大模块Home
主页, Bill
账单和Me
我的, 对应三个tab. 现在需求是 Home
push HomeTwo
, HomeTwo
push BillTwo
, BillTwo
返回到 Bill
账单首页.
首先选择路由结构, 选择使用最外层是StackNavigator
, 然后包含3个TabNavigator
和其他组件.
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},styles.icon]}/>), }, } }, Me: { screen: Me, path:'app/me', navigationOptions: { tabBar: { label: '我', icon: ({tintColor}) => (<Image source={require('./images/me.png')} style={[{tintColor: tintColor},styles.icon]}/>), }, } } }, { 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' });
在HomeTwo
里使用react-navigation
自带的reset action
就可以重置路由信息了:
// push BillTwothis.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'}) ]});
从HomeTwo
push 到 BillTwo
页面后, 点击BillTwo
的左上角导航按钮返回就能返回到Bill
账单首页了.
一般应用都有跨tab跳转的需求, 这就需要特别处理下路由. 下面是使用React-navigation
作为路由组件的一种方式.http://www.bijishequ.com/detail/369321
具体情境是: app分三大模块Home
主页, Bill
账单和Me
我的, 对应三个tab. 现在需求是 Home
push HomeTwo
, HomeTwo
push BillTwo
, BillTwo
返回到 Bill
账单首页.
首先选择路由结构, 选择使用最外层是StackNavigator
, 然后包含3个TabNavigator
和其他组件.
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},styles.icon]}/>), }, } }, Me: { screen: Me, path:'app/me', navigationOptions: { tabBar: { label: '我', icon: ({tintColor}) => (<Image source={require('./images/me.png')} style={[{tintColor: tintColor},styles.icon]}/>), }, } } }, { 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' });
在HomeTwo
里使用react-navigation
自带的reset action
就可以重置路由信息了:
// push BillTwothis.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'}) ]});
从HomeTwo
push 到 BillTwo
页面后, 点击BillTwo
的左上角导航按钮返回就能返回到Bill
账单首页了.
http://www.bijishequ.com/detail/369321
具体情境是: app分三大模块Home
主页, Bill
账单和Me
我的, 对应三个tab. 现在需求是 Home
push HomeTwo
, HomeTwo
push BillTwo
, BillTwo
返回到 Bill
账单首页.
首先选择路由结构, 选择使用最外层是StackNavigator
, 然后包含3个TabNavigator
和其他组件.
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},styles.icon]}/>), }, } }, Me: { screen: Me, path:'app/me', navigationOptions: { tabBar: { label: '我', icon: ({tintColor}) => (<Image source={require('./images/me.png')} style={[{tintColor: tintColor},styles.icon]}/>), }, } } }, { 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' });
在HomeTwo
里使用react-navigation
自带的reset action
就可以重置路由信息了:
// push BillTwothis.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'}) ]});
从HomeTwo
push 到 BillTwo
页面后, 点击BillTwo
的左上角导航按钮返回就能返回到Bill
账单首页了.
- react-navigation跨tab路由处理
- react-navigation跨tab路由处理
- React Navigation之Tab Navigator完全解析
- react-navigation路由篇之StackRouter
- React-native IT喵喵~路由之React Navigation
- React Navigation--Stack Navigator and Tab Navigator联合使用
- react-native-navigation 原生路由组件的使用
- react-navigation Navigation使用
- react-navigation
- react-navigation
- react-navigation
- react-navigation
- React Native --react-navigation
- React Native react-navigation
- navigation+tab bar
- react-native 学习 ----- React Navigation
- react-navigation 简单使用
- react-navigation使用
- javaee中针对xml的解析方式---DOM
- 关于MATLAB四连通与八连通的问题
- 2. Add Two Numbers
- uva 1587 盒子
- [FUNC]MouseIsOver
- react-navigation跨tab路由处理
- CSS选择器
- 热门工具推荐:
- Github入门
- VMware下,Hadoop集群的配置
- Allegro DRC 就当掉解决方法
- FZU2268 Cutting Game(数学,规律)(第七届福建省大学生程序设计竞赛)
- spark--transform算子--mapPartitions
- 第七届福建省赛 【(5+2)/10】