使用NavigationService在react组件之外的react native中导航,弹出,重置

时间:2019-09-07 06:40:11

标签: javascript reactjs react-native react-navigation

我将在react组件之外使用react navigation,所以我无法访问道具,我可以为navigate做这件事,但我不知道如何为{ {1}}和reset这是我对pop的代码:

navigate

2 个答案:

答案 0 :(得分:1)

首先在NavigationService中导入StackAction

import {
  NavigationActions,
  StackActions,
} from "react-navigation";

添加弹出和替换功能

function replace(routeName, params) {
  _navigator.dispatch(
    StackActions.replace({
      routeName,
      params
    })
  );
}

function pop(number = 1) {
  _navigator.dispatch(
    StackActions.pop({
      n: number
    })
  );
}

注意:“弹出”具有要弹出多少个屏幕的参数。默认值为1表示当前屏幕

答案 1 :(得分:0)

与此相关,您可以使用导航,弹出,重置:

参考:

https://reactnavigation.org/docs/en/navigation-actions.html

https://reactnavigation.org/docs/en/navigation-actions.html

struct event *event_new(
    struct event_base *,
    evutil_socket_t,
    short,
    event_callback_fn,
    void *       
)