I have the following app structure:
Main Page : Choose Login Type A or B
if the user choses login type A then navigate to > Page A1 Credentials for A type
if the user choses login type B then navigate to > Page B1 Credentials for B type
if Login is successfull for page A1 navigate to > Page A2
if Login is successfull for page B1 navigate to > Page B2
Page A1 --- Login Successful ---> Page A2
/
/
/
Page 1 \
\
\
Page B1 --- Login Successful ---> Page B2
If the user is in Page A1 or B1, I would like to allow him to go back to page 1 if he wants. However if the user logs in either using type 1 or 2 and reaches either A2 or B2, he shouldn't be allowed to go back.
Here is my code :
Before going to pages A2 or B2 I run. (This code executes in pages A1, B1) :
public static void RemoveAllPagesFromNavigation(INavigation Navigation)
{
var existingPages = Navigation.NavigationStack.ToList();
foreach (var page in existingPages)
{
if (page != null)
{
Navigation.RemovePage(page);
}
}
}
RemoveAllPagesFromNavigation(this.Navigation);
await Navigation.PushAsync(new PageA2()); // Or PageB2
But the function RemoveAllPagesFromNavigation raises an exception saying that the first element of the NavigationStack is null;
I added a condition to skip the case where the first page is null, the function runs but the end user is still able to go back to page Page 1.
Does anyone know how to prevent user from going back to the pages 1, A1 or B2 ?
Thanks.