React native ex-navigation 改变路由器
React native ex-navigation changing routers
我在使用 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'})
您是否在新页面组件的另一个函数中调用了 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'});
}
我在使用 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'})
您是否在新页面组件的另一个函数中调用了 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'});
}