我正在创建过滤器页面屏幕。.在该屏幕上,我填写了要过滤数据的所有数据后,我将单击“保存”按钮,这会将我重定向到主页,其中新过滤的数据将在该主页上显示。我的主页已经显示了常规数据,但是如果我想查看过滤器数据,那么我将从过滤器屏幕中过滤该数据。
但是这里我有问题是我无法重定向到主页。我用于重定向的代码对于我的整个应用程序都是相同的,可以正常运行。我只在重定向到主页时遇到问题,控制台中没有显示错误,但会打印我在函数中编写的消息。而不是什么也没做。
import NavigationService from '../../components/NavigationService';
onSaveClicked() {
console.log('Filter is in progress');
const { navigation } = this.props;
navigation.navigate('home');
const { userprofile } = this.props;
const { type } = userprofile;
NavigationService.navigate('HomeStackScreen1', {type:type});
}
renderButton() {
return (
<Button
style={{ alignItems: 'center' }}
onPress={this.onSaveClicked.bind(this)}
>
Filter
</Button>
);
}
navigationService.js
import { NavigationActions,navigation } from 'react-navigation';
let _navigator;
function setTopLevelNavigator(navigatorRef) {
_navigator = navigatorRef;
}
function navigate(routeName, params) {
_navigator.dispatch(
NavigationActions.navigate({
routeName,
params
})
);
}
function getParams(param){
console.log("param: "+param);
_navigator.dispatch(
console.log("param: "+param),
navigation.getParam(param)
);
}
export default { setTopLevelNavigator, navigate, getParams };
导航堆栈:
const HomeStack = createStackNavigator(
{
HomeStackScreen1: {
screen: DrawerNavigation,
navigationOptions: ({ navigation }) => ({
title: 'Action',
headerLeft: (
<DrawerButton name="navicon" style={styles.Headercss} navigation={navigation} />
),
headerRight: (
<SearchButton style={styles.Headercss} navigation={navigation} />
),
//headerStyle: { paddingRight: 5, paddingLeft: 5 },
headerTitleStyle: { color: 'rgb(234, 94, 32)' }
})
},
Project: {
screen: ProjectTab,
navigationOptions: () => ({
title: ' Create New Project',
headerTintColor: 'rgb(234, 94, 32)',
})
},
Notification: {
screen: NotificationScreen
},
Filters: {
screen: FilterScreen,
navigationOptions: () => ({
title: 'Filter',
headerTintColor: 'rgb(234, 94, 32)',
})
},
UpdateProfile: {
screen:UserProfileScreen,
navigationOptions: () => ({
title: 'Profile',
headerTintColor: 'rgb(234, 94, 32)',
})
},
ViewActorProfile: {
screen: ViewActorProfileScreen,
navigationOptions: () => ({
title: 'View Profile',
headerTintColor: 'rgb(234, 94, 32)',
})
},
ViewProducer :{
screen: ViewProducerProfile,
navigationOptions: () => ({
title: 'View Profile',
headerTintColor: 'rgb(234, 94, 32)',
})
},
ProjectView: {
screen: ViewProject,
navigationOptions: () => ({
title: 'View Project',
headerTintColor: 'rgb(234, 94, 32)',
})
},
AppliedProjectScreen: {
screen: AppliedProjectUsers,
navigationOptions: () => ({
title: 'Applied Users',
headerTintColor: 'rgb(234, 94, 32)',
})
},
ChattingScreen: {
screen: Chat,
navigationOptions: {
title: 'Chat'
}
},
ViewActorProfileScreen: {
screen: ViewActorProfileScreen,
navigationOptions: () => ({
title: 'View Profile',
headerTintColor: 'rgb(234, 94, 32)',
})
}
},
{
initialRouteName: 'HomeStackScreen1',
headerMode: 'screen'
}
);
答案 0 :(得分:2)
您必须使用确切的家庭路线名称作为导航参数:
navigation.navigate('HomeStackScreen1');
如果需要,还可以在导航堆栈上将HomeStackScreen1
重命名为Home
。