反应本机前游动路由器



我在用反应的前传动切换页面时有一个问题:错误:未定义不是对象(评估'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'})

您在新页面组件中的另一个函数中是否调用了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'});
}

相关内容

  • 没有找到相关文章

最新更新