0
votes

Xamarin.forms using Prism Navigation back is not working in below scenario :

  1. App.xaml.cs in OnInitialized NavigationService.NavigateAsync(nameof(LoginView));
  2. In LoginViewModel once login I am navigating to MainPage await _navigationService.NavigateAsync(new Uri("MainPage", UriKind.Relative),useModalNavigation:true, animated: false);
  3. MainPaga has a Button once I click in Button it will Popup setting Page navigation Popup like : await _navigationService.NavigateAsync(new Uri("SettingView", UriKind.Relative), useModalNavigation: true, animated: false);
  4. SettingView(Popup) has a Button(LogOut) once I click on Button(LogOut) it has to go back in LoginView here is the code navigating back.

                    await _navigationService.ClearPopupStackAsync(animated: false);
                await _navigationService.GoBackAsync(useModalNavigation: true, animated: false);
    

first I am Clearing Popup then navigating back, but it wont navigate back to LoginView?

2
If you ClearPopupStackAsync, won't all pages be popped from the stack? So there's no LoginView to come back to.Bruno Caceiro
then how would I go back from Popup page?Jitendra Jadav

2 Answers

3
votes

If you are using PRISM and want to 'clear' the current stack. You better use the explicit uri navigation. Meaning the code behind the logout button should look like this

await _navigationService.NavigateAsync("/NavigationPage/LoginView");

By adding the / at the beginning of the URI, the current stack will be cleared.

1
votes

You should just use absolute uri to set Loginpage as Mainpage after user confirm to logout like this

await NavigationService.NavigateAsync(new System.Uri("/LoginPage",System.UriKind.Absolute));