1、在一个页面中中引入一个组件,但是这个组件是一个小组件,例如是一个cell,单独的每个cell都是需要点击有链接跳转的,这个时候通常直接使用 onPress 的跳转就会不起作用

正确的处理方法是,在组件中封装一个点击事件,然后在父组件中执行跳转的函数

正常的跳转方法是:

import React from 'react';
import {
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
ScrollView,
} from 'react-native'; // navigator
import { StackNavigator } from 'react-navigation'; // 引入组件 Cell
import CommonCell from './commonCell'; export default class More extends React.Component { // 顶部导航
static navigationOptions = ({ navigation }) => {
const { navigate } = navigation;
return {
title: '更多',
tabBarLabel: '更多',
mode: 'card',
headerMode: 'float',
activeTintColor: '#000000',
};
}; render() {
const { navigate } = this.props.navigation;
return (
<View style={styles.container}>
<ScrollView> <View style={{marginTop: }}>
<TouchableOpacity
onPress={() => navigate('ShakeMode')} // 跳转
>
<Text>点击震动手机</Text>
</TouchableOpacity>
</View> </ScrollView>
</View>
);
} } const styles = StyleSheet.create({
container: {
flex: ,
backgroundColor: '#e8e8e8',
},
});

如果引入了组件,在组件中要跳转,方法如下

父组件:

import React from 'react';
import {
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
ScrollView,
} from 'react-native'; // navigator
import { StackNavigator } from 'react-navigation'; // 引入组件 Cell
import CommonCell from './commonCell'; export default class More extends React.Component { // 顶部导航
static navigationOptions = ({ navigation }) => {
const { navigate } = navigation;
return {
title: '更多',
};
}; render() {
const { navigate } = this.props.navigation;
return (
<View style={styles.container}>
<ScrollView>
<View style={{marginTop: }} >
<CommonCell
nextClick={() => {this.endClick()}}
title="点击震动手机"
/>
</View> </ScrollView>
</View>
);
} // 控制跳转
endClick() {
const { navigate } = this.props.navigation;
navigate('ShakeMode')
} } const styles = StyleSheet.create({
container: {
flex: ,
backgroundColor: '#e8e8e8',
},
});

引入组件

CommonCell,并将方法 nextClick = endClick,
endClick执行跳转的方法,
nextClick 传递给子组件
子组件
render() {
return (
<TouchableOpacity
onPress={this.props.nextClick}
>
<View style={styles.container}> {/**左边**/}
<Text style={{marginLeft: 10}}>{this.props.title}</Text> {/**右边 返回什么需要判断 **/}
{this.renderRightView()} </View>
</TouchableOpacity>
);
}

  这样就可以实现跳转了

基于 react-navigation 父子组件的跳转链接的更多相关文章

  1. 使用react进行父子组件传值

    在单页面里面,父子组件传值是比较常见的,之前一直用vue开发,今天研究了一下react的父子组件传值,和vue差不多的思路,父组件向子组件传值,父通过初始state,子组件通过this.props进行 ...

  2. React中父子组件间的通信问题

    1.https://blog.csdn.net/sinat_17775997/article/details/59103173 (React中父子组件间的通信问题)

  3. React中父子组件数据传递

    Vue.js中父子组件数据传递:Props Down ,  Events Up Angular中父子组件数据传递:Props Down,  Events  Up React中父子组件数据传递:Prop ...

  4. 如何基于 React 封装一个组件

    如何基于 React 封装一个组件 前言 很多小伙伴在第一次尝试封装组件时会和我一样碰到许多问题,比如人家的组件会有 color 属性,我们在使用组件时传入组件文档中说明的属性值如 primary , ...

  5. React之父子组件之间传值

    1.新增知识点 /** React中的组件: 解决html 标签构建应用的不足. 使用组件的好处:把公共的功能单独抽离成一个文件作为一个组件,哪里里使用哪里引入. 父子组件:组件的相互调用中,我们把调 ...

  6. 关于React的父子组件通信等等

    //==================================================此处为父子组件通信 1.子组件调用父组件: 父组件将子组件需要调用方法存入props属性内,子组 ...

  7. React中父子组件传值

    一.首先我们先来看父组件向子组件传值 1.1 我们要明白父组件 --> 子组件 是通过props这个属性来传值的 我们来看父组件的代码 import React from 'react'; im ...

  8. 基于react hooks,zarm组件库配置开发h5表单页面

    最近使用React Hooks结合zarm组件库,基于js对象配置方式开发了大量的h5表单页面.大家都知道h5表单功能无非就是表单数据的收集,验证,提交,回显编辑,通常排列方式也是自上向下一行一列的方 ...

  9. React之父子组件传递和其它一些要点

    react是R系技术栈中最基础同时也是最核心的一环,2年不到获取了62.5k star(截止到目前),足可见其给力程度.下面对一些react日常开发中的注意事项进行罗列. React的组件生命周期 r ...

随机推荐

  1. 在Centos安装oracle_11gR2进度68%"Error in invoking target mkldflags ntcontab.o nnfgt.o of makefile..”

    http://www.xwood.net/_site_domain_/_root/5870/5874/t_c265367.html

  2. [bzoj3529][Sdoi2014]数表_树状数组_莫比乌斯反演

    数表 bzoj-3529 Sdoi-2014 题目大意:n*m的数表,第i行第j列的数是同时整除i和j的所有自然数之和.给定a,求数表中所有不超过a的和. 注释:$1\le n,m \le 10^5$ ...

  3. [poj3974]Palindrome_Manacher

    Palindrome poj-3974 题目大意:求字符串的最长回文子串. 注释:$1\le strlen(s) \le 10^6$. 想法:介绍一种字符串算法——Manacher.求以每一个字符和字 ...

  4. [Node.js] Add Logging to a Node.js Application using Winston

    Winston is a popular logging library for NodeJS which allows you to customise the output, as well as ...

  5. mysql数据类型和Java数据类型对比一览

    MySQL Types to Java Types for ResultSet.getObject() MySQL Type Name Return value ofGetColumnClassNam ...

  6. JavaScript模式读书笔记 第4章 函数

    2014年11月10日 1.JavaScript函数具有两个特点: 函数是第一类对象    函数能够提供作用域         函数即对象,表现为:         -1,函数能够在执行时动态创建,也 ...

  7. Rockchip平台TP驱动详解【转】

    本文转载自:http://blog.csdn.net/encourage2011/article/details/51679332 本文描述在RK3126平台上添加一个新的TP驱动(gslx680驱动 ...

  8. poj 1741(树的点分治)

    Tree Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dis ...

  9. PCB MS SQL 通过表名查询各字段信息和vb.net C# module类代码

    正式表:各字段内容获取 ) SET @tabname = 'ppeflow' SELECT @tabname AS '表名' ,(CASE ))+ ')' )) ) )) + ')' )) ) )) ...

  10. [Apple开发者帐户帮助]三、创建证书(4)创建Safari签名证书

    您的Safari扩展程序必须由Apple颁发的证书签名,您可以在开发者帐户中创建和下载该证书. 在“ 证书”,“标识符和配置文件”中,从左侧的弹出菜单中选择“Safari扩展”. 在“证书”下,选择“ ...