我正在尝试从 Form.js 访问“主页”。但是我的代码显示了那个错误。我该如何解决?
我在 arrowF、routes 中尝试过,但没有任何效果。同样的错误...
This is my Form.js where I call onPress=() I tried function, navigation and nothing works. I try add const { navigation } = this.props; and nothing works. Same error.
<View style={styles.viewChild}>
<TouchableHighlight
onPress={this._Home} title="Home"
style={styles.button} >
<Text style={{color: '#fff', fontSize: 16}}>Acessar</Text>
</TouchableHighlight>
This is my Login.js. Where I call Component
import React from 'react';
import {
Container, Top, Logo, Title, Content
} from './styles';
import Form from '~/components/Form/form';
import logo from '~/assets/logo.png';
import { MaterialTopTabBar, navigation } from 'react-navigation';
export default function Login(){
return (
<Container>
<Top>
<Logo source={logo} />
<Title
style={MaterialTopTabBar.display1}
>Welcome</Title>
</Top>
<Content>
<Form />
</Content>
</Container>
);
}
This is my Route.js I tried changes between Stack, BottomNav, and nothing works. The Route from Form.js to 'Home' failed. I can post my GitHub.
import { createAppContainer, createSwitchNavigator, createStackNavigator
} from 'react-navigation';
import Form from '~/components/Form/form';
import Home from '~/pages/Home/home';
import Main from '~/pages/Main';
const Routes = createAppContainer(
createSwitchNavigator({
Main: {screen: Main},
Form: {screen: Form},
Home: {screen: Home,
navigationOptions: {
title: 'Home',
headerBackTitle: null,
}}
}),
);
export default Routes;
最佳答案
函数使用如下:
func1(){
this.props.navigation.navigate("Form");
}
...
<TouchableHighlight
onPress={this.func1.bind(this)} title="Home"
or
<TouchableHighlight
onPress={() => this.func1()} title="Home"
使用箭头函数
const func1 = () => {
this.props.navigation.navigate("Form");
}
...
<TouchableHighlight
onPress={this.func1} title="Home"
关于javascript - undefined 不是一个函数(评估'_this.props.navigation.navigate'),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57294869/