我正在尝试将道具从登录屏幕传递到整个应用程序,因为每个获取请求都依赖于用户凭据,所以我该如何实现这一点。
路由配置文件:
export const sendStack = StackNavigator({
send:{
screen:Send,
},
confirm:{
screen:ConfrimPay,
}
});
export const transactionStack = StackNavigator({
transaction:{
screen:Transaction,
},
details:{
screen:Details,
}
});
export const Tab=TabNavigator({
send:{
screen:sendStack,
},
receivers:{
screen:Receipt,
tabBar:{
swipeEnabled:false
}
},
transaction:{
screen:transactionStack
},
},
{
tabBarPosition: 'bottom',
swipeEnabled: false,
tabBarOptions: {
activeTintColor: 'white',
labelStyle:{
fontSize:5
}
}
}
);
export const Logst =StackNavigator({
first:{
screen:First
},
login:{
screen:App ,
},
tab:{
screen:Tab,
},
},
{
headerMode: 'none',
navigationOptions: {
headerVisible: false,
}
});
根导航:
import React, { Component } from 'react';
import {Tab, Logst,Root} from './mainNav';
import App from './App';
class List extends Component {
render() {
return(<Logst />) ;
}
}
这是我的登录页面,我使用 this.props.navigation.navigate('tab',{user:user,pwd:pwd}); 它给了我一个错误,这意味着道具尚未通过
this.props.navigation.navigate('tab',{user:user,pwd:pwd});
+this.props.navigation.state.params.user+'&pwd='+this.props.navigation.state.params.pwd+'&func=2
注意*我将道具从 stackNav 传递到嵌套在 TabNav 中的 stackNav