0
votes

We're starting on a Xamarin.Forms app, and there are going to be quite a few pages and the navigation between pages will be handled completely by the app - specifically there is no back button, which shouldn't be a problem since we are only planning on releasing for iOS.

The first page the user encounters is the Login page, once logged in they go to the Home page. To perform this transition I just call

LoginPage.Navigation.PushModalAsync(HomePage)

and that's fine.

Now if, on the Home page, they press the Logout button, I could call PopModalAsync(), the problem is that the Logout button exists on all the pages, so the user could have followed a path like this:

Login -> Home -> Create -> Format -> Print -> Logout

and I need to immediately jump to the Login screen.

So on the Home page, if the user presses the Logout button, I tried calling

ApplicationHomePage.Navigation.PushModalAsync(LoginPage);

but got an exception:

System.InvalidOperationException: Page must not already have a parent.

So just for fun I thought I'd try the easy solution:

LoginPage.Parent = null;
ApplicationHomePage.Navigation.PushModalAsync(LoginPage);

I'm never going to have a back button, and the iPad doesn't have one, so the contents of the navigation stacks aren't really important (right?)

Is this method of navigating "legal"? Is it going to cause me some problem I'm not seeing right now?

1
having your entire app displayed as a modal seems like a bad idea. I would instead launch your HomePage (or some placedholder) as your root and display Login as a modal. After they login, dismiss the modal. When they logout, Pop to root and then display the modal again. Or there are a lot of other approaches you could use.Jason

1 Answers

1
votes

I think you can take a look to this

You should don't add your login page to a NavigationStack. Change MainPage property is a good solution...