首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >导航在app.js中的appcontainer外部导航

导航在app.js中的appcontainer外部导航
EN

Stack Overflow用户
提问于 2020-08-19 23:42:53
回答 1查看 133关注 0票数 0

当前行为

我使用react导航v4x未定义的不是对象navigation.discpatch

预期行为

我想在appcontainer `中导航登录页面

代码语言:javascript
复制
export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {isFirstLaunch: false, hasCheckedAsyncStorage: false};
    const myRef = createRef();
  }

  onPressLogin() {
    this.navigator.dispatch(
      NavigationActions.navigate({ routeName: 'Login' })
    );
  }
  async componentDidMount() {
    const isFirstLaunch = await checkIfFirstLaunch();
    this.setState({isFirstLaunch, hasCheckedAsyncStorage: true});
  }

  render() {
    const {hasCheckedAsyncStorage, isFirstLaunch} = this.state;

    if (!hasCheckedAsyncStorage) {
      return null;
    }
    return isFirstLaunch ? (
      <EntryInfo onPress={this.onPressLogin} />
    ) : (
      <AppContainer
        ref={nav => {
          setTopLevelNavigator(nav);
          this.navigator = nav;
        }}
      />
    );
  }
}`

软件版本android反应-导航4.4.0反应-导航-栈2.8.2反应-本机0.62.2

EN

回答 1

Stack Overflow用户

发布于 2020-08-20 00:58:51

在导航之前,只需确保导航器存在。它对我来说很有效

代码语言:javascript
复制
function setTopLevelNavigator(navigatorRef) {
if(navigatorRef)
{
   navigator = navigatorRef;
}
  
}

function navigate(routeName, params) {
  if(navigator && routeName){
   navigator.dispatch(
    NavigationActions.navigate({
      routeName,
      params,
    })
  );
  }
  
}

// add other navigation functions that you need and export them

export default {
  navigate,
  setTopLevelNavigator,
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63490570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档