如何将动态定义的导航器连接到react-native中的redux

时间:2017-10-14 18:06:56

标签: javascript mobile react-native redux react-navigation

如何通过函数调用动态创建导航器到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'
});

0 个答案:

没有答案