React native _此2.props.navigator.push不是一个函数
我试图在React本机应用程序中使用Navigator,但遇到了一些问题 在应用程序开始时,我正在加载此LoginScreen组件:React native _此2.props.navigator.push不是一个函数,react-native,React Native,我试图在React本机应用程序中使用Navigator,但遇到了一些问题 在应用程序开始时,我正在加载此LoginScreen组件: return <LoginScreen navigator={navigator}/>; 如何解决这个问题?当我尝试在navigator中使用tabview时,也遇到了同样的问题。然后我在返回我的视图时添加了{…this.props} 返回 这里还有一个关于如何使用导航器的代码示例,希望能对您有所帮助 我创建了一个navigator类: 'use s
return <LoginScreen navigator={navigator}/>;
如何解决这个问题?当我尝试在navigator中使用tabview时,也遇到了同样的问题。然后我在返回我的视图时添加了{…this.props}
返回代码>
这里还有一个关于如何使用导航器的代码示例,希望能对您有所帮助
我创建了一个navigator类:
'use strict';
const React = require('React');
const Navigator = require('Navigator');
const LoginScreen = require('../login/LoginScreen');
const UserFlowScreen = require('../userFlow/UserFlowScreen');
class MyAppNavigator extends React.Component{
constructor(props) {
super(props);
}
render() {
return (
<Navigator
ref="appNavigator"
style={styles.container}
initialRoute={this.props.initialRoute}
renderScene={this._renderScene}
configureScene={(route) => ({
...route.sceneConfig || Navigator.SceneConfigs.FloatFromRight
})}
/>
);
}
_renderScene(route, navigator) {
var globalNavigatorProps = { navigator }
switch (route.ident) {
case "LoginScreen":
return <LoginScreen {...globalNavigatorProps} />
case "UserFlowScreen":
return <UserFlowScreen {...globalNavigatorProps} />
default:
return <LoginScreen {...globalNavigatorProps} />
}
}
};
module.exports = MyAppNavigator;
“严格使用”;
const React=require('React');
const Navigator=require('Navigator');
const LoginScreen=require('../login/LoginScreen');
const UserFlowScreen=require('../userFlow/UserFlowScreen');
类MyAppNavigator扩展了React.Component{
建造师(道具){
超级(道具);
}
render(){
返回(
({
…route.SceneFig | | Navigator.SceneFig.FloatFromRight
})}
/>
);
}
_renderScene(路线、导航器){
var globalNavigatorProps={navigator}
道岔(路线识别){
案例“登录筛选”:
返回
案例“UserFlowScreen”:
返回
违约:
返回
}
}
};
module.exports=MyAppNavigator;
然后在我的主视图中,我调用我的导航器:
'use strict';
const React = require('React');
const {
Text,
View,
} = React;
const MyAppViewContainer = require('./common/MyAppViewContainer');
const MyAppNavigator = require('./common/MyAppNavigator');
class MyApp extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<MyAppViewContainer >
<MyAppNavigator initialRoute={{ident: "LoginScreen"}} />
</MyAppViewContainer >
);
}
};
module.exports = MyApp;
“严格使用”;
const React=require('React');
常数{
文本,
看法
}=反应;
const MyAppViewContainer=require('./common/MyAppViewContainer');
const MyAppNavigator=require('./common/MyAppNavigator');
类MyApp扩展了React.Component{
建造师(道具){
超级(道具);
}
render(){
返回(
);
}
};
module.exports=MyApp;
在我的登录屏幕中,我可以直接推到userFlowScreen:
'use strict';
const React = require('React');
const ReactNative = require('react-native');
const{
Text,
View,
TouchableOpacity,
Navigator,
} = ReactNative;
class LoginScreen extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<View>
<TouchableOpacity onPress={() => this._pressRow()}>
<Text>Login</Text>
</TouchableOpacity>
</View>
);
}
_pressRow(){
this.props.navigator.push({
ident: "UserFlowScreen",
sceneConfig: Navigator.SceneConfigs.FloatFromRight,
});
}
};
module.exports = LoginScreen;
“严格使用”;
const React=require('React');
const ReactNative=require('react-native');
常数{
文本,
看法
可触摸不透明度,
领航员,
}=反应性;
类LoginScreen扩展了React.Component{
建造师(道具){
超级(道具);
}
render(){
返回(
这是。\按Row()}>
登录
);
}
_pressRow(){
这个是.props.navigator.push({
标识:“用户流屏”,
SceneFig:Navigator.SceneFigs.FloatFromRight,
});
}
};
module.exports=登录屏幕;
您可以通过以下方式完成:
componentDidMount () {
const {navigation} = this.props;
navigation.addListener ('willFocus', () =>
// run function that updates the data on entering the screen
);
}
我这样使用:return( )代码>是否必须将此更改为
?@userashu19您可以将其保持为{…route.passProps}
但如果我保持为{…route.passProps}
那么为什么我会得到错误,因为未定义不是一个对象(评估'this.props.navigator')
'use strict';
const React = require('React');
const {
Text,
View,
} = React;
const MyAppViewContainer = require('./common/MyAppViewContainer');
const MyAppNavigator = require('./common/MyAppNavigator');
class MyApp extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<MyAppViewContainer >
<MyAppNavigator initialRoute={{ident: "LoginScreen"}} />
</MyAppViewContainer >
);
}
};
module.exports = MyApp;
'use strict';
const React = require('React');
const ReactNative = require('react-native');
const{
Text,
View,
TouchableOpacity,
Navigator,
} = ReactNative;
class LoginScreen extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<View>
<TouchableOpacity onPress={() => this._pressRow()}>
<Text>Login</Text>
</TouchableOpacity>
</View>
);
}
_pressRow(){
this.props.navigator.push({
ident: "UserFlowScreen",
sceneConfig: Navigator.SceneConfigs.FloatFromRight,
});
}
};
module.exports = LoginScreen;
componentDidMount () {
const {navigation} = this.props;
navigation.addListener ('willFocus', () =>
// run function that updates the data on entering the screen
);
}