如何通过函数调用动态创建导航器到redux? 根据授权状态(token!= null),LoginNavigator的初始路由正在改变。
代码:
App.js
linha_aux
登录导航器:
import createLoginNavigator from './navigators/LoginNavigator';
class App extends Component {
render() {
const LoginNavigator = createLoginNavigator(this.props.token !== null);
return <LoginNavigator/>;
}
}
const mapStateToProps = ({ auth }) => ({
token: auth.get('token')
});
export default connect(mapStateToProps, null)(App);
我不能在导航reducer中调用此函数,因为它将是其他路由器:
import LoginPage from '../pages/LoginPage';
import RootNavigator from '../navigators/RootNavigator';
export default createLoginNavigator = (authState) => StackNavigator({
Login: { screen: LoginPage },
RootNavigator: { screen: RootNavigator }
}, {
initialRouteName: authState ? 'RootNavigator' : 'Login'
});