maui
maui copied to clipboard
GoToAsync returns user to desired page but previous page's OnAppearing() is triggered
Description
When navigating pages with GoToAsync()
in Shell, changing page hierarchy will result in OnAppearing() being called on a page that is not in the target navigation url/stack.
Steps to Reproduce
- Run app on Android (or iOS) (current:
//MainPage
) - Click
Go to Page 1
(current://MainPage/Page1
) - Click
Go to Page 2
(current://MainPage/Page1/Page2
) - Click
Go to SubMainPage
(current://MainPage/SubMainPage
) - Open Flyout or Command and click
Return to MainPage
(current://MainPage
)
When Return to MainPage
is clicked, the command is executing the following await Shell.Current.GoToAsync($"//{nameof(MainPage)}");
. This should return the user directly to the page based on the URL, however, OnAppearing
will be triggered for Page2
, which is unwanted and not desired.
Routes for MainPage
and SubMainPage
are defined in AppShell.xaml
, where Page1
and Page2
are using RegisterRoute
in AppShell.xaml.cs
as to only show Back button.
Link to public reproduction project repository
https://github.com/d-harding/maui-pageflow
Version with bug
Unknown/Other
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, I was not able test on other platforms
Affected platform versions
No response
Did you find any workaround?
No
Relevant log output
No response
Possibly related to this issue (same root cause?) there are already known issues with OnAppearing() and IsPresented not running at the correct times (in this case with a Flyout menu, with no Shell being used). See https://github.com/dotnet/maui/issues/15767
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.
Verified this on VS 17.10.0 Preview 1.0(8.0.6). Repro on Windows 11, Android 14.0-API34, iOS 17.2 and MacCatalyst with below Project: maui-pageflow.zip