Xamarin.Forms Shell Login Page Flow
Why Stack Overflow recommends it
Stack Overflow users link it when asking how to structure a login page and main app flow with Shell navigation, in Xamarin.Forms and later .NET MAUI.
Recommended by 3 people across 3 different months, 2021 to 2024.
What it is
A 14-minute Xamarin.Forms tutorial by James Montemagno on building a login flow with Shell and URL-based navigation. It walks through the code, absolute versus relative routes, and logging out while saving login info.
What people said
Strong rec Rizwan Siddiqui · 2021-09 · Stack Overflow · on “Defining layout of a crossplatform mobile app in c# (xamarin forms) using Shell”
I found the answer by watching a couple of videos by James Montemagno on youtube. If you are new to xamarin, I highly recommend these videos! [this video] - Login flow [LINK] - Shell Navigation
Recommends Sam · 2022-07 · Stack Overflow · on “Login page shows briefly even if user is logged into .NET MAUI app”
Thanks. This will work but I'm still confused. I was following James M.'s approach as he demonstrated in this video. In his case, it seems to work fine [this video]
Recommends Reza · 2024-09 · Stack Overflow · on “Navigating to LoginPage/MainPage on app start”
I found two articles referring to AppShell in Xamarin.Forms and how to handle checking for authenticated users. The Xamarin articles are identical to a Maui solution. (1) [this video] James navigates to a login page and checks authentication using the OnAppearing method. He also mentions that this can be done either on the Login page or in AppShell (which is where I perform my check in the code posted in the question). (2) [LINK] Mark uses an intermediary loading page between when the app starts and painting either the login page or main page. This seems a little overkill, but posting here in case anyone has an opinion. I will continue with option (1).
Cites Bas H · 2022-05 · Stack Overflow · on “Xamarin Shell: Redirect to different page and remove current page from nav stack”
You can try this. //route The route hierarchy will be searched for the specified route, upwards from the current position. The matching page will replace the navigation stack. [LINK] await Shell.Current.GoToAsync($"//{nameof(AddNewDataPage)}"); [this video] An explanation about relative routes.