React native 导航操作。导航不工作
执行导航操作时,我需要导航到某个路线。 我阅读了文档,但没有解决我的问题。 我正在使用Redux saga和React导航v5React native 导航操作。导航不工作,react-native,React Native,执行导航操作时,我需要导航到某个路线。 我阅读了文档,但没有解决我的问题。 我正在使用Redux saga和React导航v5 import {put, call, select} from 'redux-saga/effects'; import {apiGet, apiGetProdutoByID} from '../../services/overAll/apiProdutos'; import {TypesProdutos} from './../ducks/produtos'; imp
import {put, call, select} from 'redux-saga/effects';
import {apiGet, apiGetProdutoByID} from '../../services/overAll/apiProdutos';
import {TypesProdutos} from './../ducks/produtos';
import {NavigationActions} from 'react-navigation';
export function* searchByID(action) {
try {
const response = yield call(apiGetProdutoByID, action.idProduto);
yield put({
type: TypesProdutos.SEARCH_BY_ID,
produto: response.data.data.obj,
});
const produto = yield select(state => state.produtos.dataByID);
console.log(produto);
**yield put(
NavigationActions.navigate({
routeName: action.route,
params: {produto: produto},
}),
);**
} catch (error) {
console.log(error);
yield put({type: TypesProdutos.FAIL});
}
}
仔细阅读react navigation的文档,我找到了NavigationRef,它提供了应用程序的任何文件的导航。因此,我使用以下代码创建了一个文件根导航: //RootNavigation.js
import * as React from 'react';
export const navigationRef = React.createRef();
export function navigate(name, params) {
navigationRef.current?.navigate(name, params);
}
在NavigationContainer组件上:
import {navigationRef} from './routes/RootNavigation';
...
<NavigationContainer ref={navigationRef}>
...
<NavigationContainer />
它起作用了 React navigation v5没有React navigation这样的软件包,您需要遵循指南
export function* searchByID(action) {
try {
...
**RootNavigation.navigate(action.route, {produto: produto});**
} catch (error) {
console.log(error);
yield put({type: TypesProdutos.FAIL});
}
}