React Native Router Flux:使用相同场景但使用其他参数的转换和历史 [英] React Native Router Flux: Transition and history using this same scene but with other parameters

查看:57
本文介绍了React Native Router Flux:使用相同场景但使用其他参数的转换和历史的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个商店应用程序,我使用 react-native-router-flux 作为路由器.目前,我只有几个场景,例如产品列表、产品信息、购物车和结帐.

I'm creating a shop app and I'm using react-native-router-flux as a router. Currently, I have just few scenes like product list, product info, basket and checkout.

但我需要创建一个导航.我有整个导航结构的 JSON,其中类别 ID 是 ProductList 场景调用 componentDidMount() 时调用 API 的 ID.

But I need to create a navigation. I have JSON with whole navigation structure, where ID of category is the ID for call to API when ProductList scene calls componentDidMount().

但我不知道如何:

a) 使用相同的场景,但有额外的参数并刷新它——我想我应该做类似 Actions.refresh({ key: PRODUCT_LIST, params: { categoryId: 12345 } }) ?

a) use this same scene but with additional parameters and refresh it -- I suppose that I should do something like Actions.refresh({ key: PRODUCT_LIST, params: { categoryId: 12345 } })?

b) 如何处理相同的场景转换历史?我的意思是,如果我要做一些 Actions.refresh(),我怎样才能回到我之前刷新的以前的类别?

b) how to handle this same scene transitions history? I mean if I'll do some Actions.refresh() how can I go back to previous categories I refreshed before?

作为应用程序中的状态管理器,我使用的是 Redux.但我没有将它用于路由器(我在配对 RNRF 和 Redux 时遇到了一些问题).

As a state manager in the app, I'm using Redux. But I'm not using it for router (I had some issues to pair RNRF and Redux).

或者您对如何处理这种情况有其他想法?

Or maybe you have other ideas how to handle this case?

最好的问候,马辛

推荐答案

解决这个问题的2种方法:

2 way for solve this problem :

1:从您的特殊组件创建两个场景,如下所示:

1: Create two Scenes from the your special component like this :

<Scene key="one" component={Home}/>
<Scene key="two" component={Home}/>

2: 是的,您可以在 Actions.refresh({ param1: 'someData'}); 中设置参数之后,您可以在道具中访问这些!像这样:

2: And yes you can set params in your Actions.refresh({ param1: 'someData'}); And after that you have access to these in your props! like this:

console.log(this.props.param1);

这篇关于React Native Router Flux:使用相同场景但使用其他参数的转换和历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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