我正在创建过滤器页面屏幕..在此屏幕上,一旦我填写了我想要过滤数据的所有数据,我将点击保存按钮,这将重定向到我将显示新过滤数据的主页。我的主页已显示一般数据,但如果我想查看过滤数据,那么我将从过滤器屏幕过滤该数据。 但在这里我有问题是我无法重定向到主页。我用于重定向的代码对于整个我的应用程序都是一样的,它完全正常工作。我只有重定向到主页的问题,并且控制台中没有显示错误但是打印了我在函数中编写的消息。而不是什么都没做。
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'
}
);
您必须使用确切的归属路由名称作为导航参数:
navigation.navigate('HomeStackScreen1');
如果需要,您还可以在导航堆栈上将HomeStackScreen1
重命名为Home
。