我是 RN 和 JS 的新手。
我想在登录操作完成后进行导航,但无法使其工作。我正在使用 firebase。
这是来自我的操作文件。它抛出一个 firebase 错误:
export const LOGIN_USER_SUCCESS = 'login_user_success';
export const loginUserSuccess = (dispatch, user) => {
dispatch({
type: LOGIN_USER_SUCCESS,
payload: user
});
this.props.navigation.navigate('groupMain'); // this doesnt work
};
我还尝试将其放入登录组件中 - 这可能是朝着正确方向迈出的一步,因为没有 firebase 错误,但什么也没有发生。所以看起来一切都有效,除了用户没有导航到正确的屏幕。 (我从上面删除了“这不起作用”行)
componentWillReceiveProps(nextProps) {
this.onAuthComplete(nextProps);
}
onAuthComplete(props) {
if (props.user) {
this.props.navigation.navigate('groupMain');
}
}
后来,我也在官方文档中找到了这一点,并尝试在我的操作中使用此代码来实现,但它引发了 firebase 错误:
“dispatch - 向路由器发送操作
使用调度将任何导航操作发送到路由器。其他导航功能在幕后使用调度。
请注意,如果您想调度反应导航操作,您应该使用此库中提供的操作创建器。
有关可用操作的完整列表,请参阅导航操作文档。
import { NavigationActions } from 'react-navigation'
const navigateAction = NavigationActions.navigate({
routeName: 'Profile',
params: {},
// navigate can have a nested navigate action that will be run inside the child router
action: NavigationActions.navigate({ routeName: 'SubProfileRoute'})
})
this.props.navigation.dispatch(navigateAction)"
thanks!