我在React Native中使用react-navigation v2,并且每当我想返回到根导航器中的某个路由时都会被卡住。
我有以下路由堆栈:
var allmonths = [
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
'January',
'February',
'March'
];
var customers = [];
$.each(dashCustomerData, function(index) {
var thisMonth = (dashCustomerData[index].getMonth);
var thisCount = (dashCustomerData[index].req_count);
$.each(allmonths, function(index) {
test = 0;
if (thisMonth == allmonths[index])
customers.push(thisCount);
else
customers.push('0');
})
});
我现在处于const HomeStack = createStackNavigator(
{
Home: Home,
CreateInvoice: CreateInvoiceScreen,
InvoiceSummary: InvoiceSummaryScreen,
PinEntry: PinEntryScreen
},
{
navigationOptions: {
header: null
}
}
);
const CustomersStack = createStackNavigator(
{
Customers: CustomersScreen,
Details: CustomerDetailsScreen
},
{
navigationOptions: {
header: null
}
}
);
const Tab = createBottomTabNavigator(
{
Home: HomeStack,
Transactions: TransactionsTab,
Customers: CustomersStack,
Settings: SettingsTab
}
);
const Routers = createStackNavigator({
splash: {
screen: SplashScreen,
navigationOptions: {...navigationOptions}
},
login: {
screen: LoginScreen,
navigationOptions: {...navigationOptions}
},
home: {
screen: HomeScreen,
navigationOptions: {...navigationOptions}
}
});
路线,我想注销并返回到Home
路线。我尝试使用以下代码:
login
但是,我没有结果,它仍然停留在_goBackToLogin() {
const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'Home' })]
});
const goToLogin = NavigationActions.navigate({
routeName: 'login'
});
this.props.navigation.dispatch(resetAction);
this.props.navigation.dispatch(goToLogin);
}
路线上。我的代码有什么问题?
答案 0 :(得分:0)
您是否将导航器选项卡和路由器组合到一个导航器中,如下所示?
const Routers = createStackNavigator({
splash: {
screen: SplashScreen,
navigationOptions: {...navigationOptions}
},
login: {
screen: LoginScreen,
navigationOptions: {...navigationOptions}
},
home: {
screen: HomeScreen,
navigationOptions: {...navigationOptions}
},
Tab: Tab
});
_goBackToLogin与您的相同。