我在使用react-native ex-navigation切换页面时遇到问题: 错误:undefined不是对象(评估'this.props.navigator'
这是代码:
import React, { Component } from 'react';
import {AppRegistry, StyleSheet, Text, View, Navigator, Button } from 'react-native';
import {createRouter, NavigationProvider, StackNavigation, TabNavigation,TabNavigationItem as TabItem,}from '@exponent/ex-navigation';
import * as firebase from "firebase";
firebase.initializeApp(config);
import Login from 'auth/firstPage'
var Register = require('auth/register')
var Tab = require('./src/components/tab/mainTab');
const Router = createRouter(() => ({
login: () => Login,
register: () => Register,
tab: () => Tab,
}));
export default class main extends Component {
componentWillMount(){
this.setState({ name:'login'});
}
constructor(props) {
super(props);
this.state = {
name: 'tab'
};
}
render(){
return(
<NavigationProvider router={Router}>
<StackNavigation initialRoute={Router.getRoute(this.state.name)} />
</NavigationProvider>
)
}
}
这是我用来导航的代码:this.props.navigator.push({name:'register'})
答案 0 :(得分:0)
您是否在新页面组件的另一个函数中调用this.props.navigator?
您需要在新的页面构造函数中添加以下内容,以便访问this.props.navigator:
constructor(props){
super(props);
this.FUNCTION_CALL_NAV = this.FUNCTION_CALL_NAV.bind(this);
}
FUNCTION_CALL_NAV() {
this.navigator.push({name: 'register'});
}