React native navigation.navigate在react native中不起作用
我正在创建筛选页面屏幕。。在这个屏幕上,一旦我填写了所有我想过滤的数据,我将点击保存按钮,这将把我重定向到主页,在那里我将显示新的过滤数据。我的主页已经显示了常规数据,但如果我想查看过滤数据,我将从过滤屏幕中过滤该数据。React native navigation.navigate在react native中不起作用,react-native,react-navigation,React Native,React Navigation,我正在创建筛选页面屏幕。。在这个屏幕上,一旦我填写了所有我想过滤的数据,我将点击保存按钮,这将把我重定向到主页,在那里我将显示新的过滤数据。我的主页已经显示了常规数据,但如果我想查看过滤数据,我将从过滤屏幕中过滤该数据。 但这里我的问题是我不能重定向到主页。我用于重定向的代码与我的整个应用程序相同,工作正常。我只在重定向到主页时遇到问题,控制台中没有显示错误,但会打印我在函数中编写的消息。而不是什么都不做 import NavigationService from '../../componen
但这里我的问题是我不能重定向到主页。我用于重定向的代码与我的整个应用程序相同,工作正常。我只在重定向到主页时遇到问题,控制台中没有显示错误,但会打印我在函数中编写的消息。而不是什么都不做
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>
);
}
导航堆栈:
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'
}
);
const HomeStack=createStackNavigator(
{
主页屏幕1:{
屏幕:抽屉驱动,
导航选项:({navigation})=>({
标题:“行动”,
左校长:(
),
头灯:(
),
//headerStyle:{paddingRight:5,paddingLeft:5},
headerTitleStyle:{color:'rgb(234,94,32)}
})
},
项目:{
屏幕:项目选项卡,
导航选项:()=>({
标题:“创建新项目”,
HeaderIntColor:“rgb(234,94,32)”,
})
},
通知:{
屏幕:通知屏幕
},
过滤器:{
屏幕:过滤器屏幕,
导航选项:()=>({
标题:“过滤器”,
HeaderIntColor:“rgb(234,94,32)”,
})
},
更新配置文件:{
屏幕:UserProfileScreen,
导航选项:()=>({
标题:“个人资料”,
HeaderIntColor:“rgb(234,94,32)”,
})
},
ViewActorProfile:{
屏幕:ViewActorProfileScreen,
导航选项:()=>({
标题:“视图配置文件”,
HeaderIntColor:“rgb(234,94,32)”,
})
},
ViewProducer:{
屏幕:ViewProducerProfile,
导航选项:()=>({
标题:“视图配置文件”,
HeaderIntColor:“rgb(234,94,32)”,
})
},
项目视图:{
屏幕:ViewProject,
导航选项:()=>({
标题:“查看项目”,
HeaderIntColor:“rgb(234,94,32)”,
})
},
AppliedProjectScreen:{
屏幕:AppliedProjectors,
导航选项:()=>({
标题:“应用用户”,
HeaderIntColor:“rgb(234,94,32)”,
})
},
聊天屏幕:{
屏幕:聊天,
导航选项:{
标题:“聊天”
}
},
ViewActorProfileScreen:{
屏幕:ViewActorProfileScreen,
导航选项:()=>({
标题:“视图配置文件”,
HeaderIntColor:“rgb(234,94,32)”,
})
}
},
{
initialRouteName:“HomeStackScreen1”,
headerMode:“屏幕”
}
);
您必须使用准确的主路线名称作为导航参数:
navigation.navigate('HomeStackScreen1')代码>
如果需要,还可以将导航堆栈上的HomeStackScreen1
重命名为Home
导航服务。导航(“主页”)工作正常吗?另外,您可以使用back()吗?您可以发布您的导航堆栈
文件吗?home在哪里注册?@JulienMalige no-NavigationService.navigate('home')不工作。我还没有试过返回(),但我现在正在努力,正如@PritishVaidya所说的,发布你的发布你的导航堆栈可以有所帮助。是的,我已经更新了代码,请检查并让我知道。是的,goBack()工作正常,但我还想将数据发送到主页,这将是我筛选的数据。是的,它工作正常,但“导航。导航('home');”这也应该有效,因为我以前已经使用过它,而且我没有发现任何问题,可能是堆栈中有另一个名为home
的路由,或者您刚刚重命名了它Navigate()
只需使用键。@MahiParmar如果我的答案解决了您的问题,感谢您接受:)我还有一个困惑:如何从筛选屏幕传递参数并在主页上重试。您将在文档中找到所有答案。。。
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'
}
);