从 React-Navigation V4 - V5 迁移 CommonActions.init 和 router.getStateForAction 发生了什么? [英] Migrating from React-Navigation V4 - V5 what happened to CommonActions.init and router.getStateForAction?

查看:42
本文介绍了从 React-Navigation V4 - V5 迁移 CommonActions.init 和 router.getStateForAction 发生了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序使用 CommonActions.init() 并将其传递给 router.getStateForAction

Our app uses CommonActions.init() and passes it to router.getStateForAction

这里有两个问题:

  1. init() 函数不再在CommonActions 中.

router.getStateForAction 在我的 AppNavigator 中不再可用.

the router.getStateForAction is no longer available from my AppNavigator.

如何使用 React-Navigation v5 执行这些功能?

How do I perform these functions with React-Navigation v5?

我的 AppNavigator 是使用兼容层创建的.如下所示:

My AppNavigator is created using the compatibility layer. It looks like the following:

const AppNavigator = createCompatNavigatorFactory(createStackNavigator)

我的应用程序抛出一个错误,指出 AppNavigator.router 未定义.那么我如何访问 router.getSateForAction 功能呢?

My app is throwing an error saying that AppNavigator.router is undefined. So how do I access the router.getSateForAction functionality as well?

推荐答案

React Navigation 5 没有这样的静态属性,因为它需要支持动态路由.要覆盖操作发生的情况,您需要传递自定义路由器.

React Navigation 5 doesn't have static properties like this because it needs to support dynamic routing. To override what happens for actions, you need to pass a custom router.

这篇关于从 React-Navigation V4 - V5 迁移 CommonActions.init 和 router.getStateForAction 发生了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆