maui icon indicating copy to clipboard operation
maui copied to clipboard

.NET MAUI Push then Pop - ambiguous routes on MAIN

Open AndrewMaisey opened this issue 1 year ago • 8 comments

Description

When I push a page to the stack and then pop the navigation framework seems to work up to two levels. When I go above two I get an ambiguous routes error when popping back and a message about mainpage.

This thread https://learn.microsoft.com/en-us/answers/questions/1193303/appshell-failed-to-navigate-back-ambiguous-routes?page=1&orderby=Helpful&comment=answer-1192252#newest-answer-comment - discusses a similar issue and I don't think it is related to the route definitions, rather the pushing and popping. I believe my routes are correct. I did a simple test harness app also to confirm this issue.

Seems to be the same issue on iOS and Android so have not seen platform differences.

Can I confirm expected behaviour please or workaround/resolution if this is a bug? Thanks.

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

8.0.3 GA

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

I have implemented my project with Gotos which is less than ideal and as discussed in the docs. GotoAsync etc. https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/shell/navigation?view=net-maui-8.0#absolute-routes

Relevant log output

No response

AndrewMaisey avatar Apr 02 '24 10:04 AndrewMaisey

Could you please create an example showing what you're talking about? I'm not sure based on what you're saying what you're doing, so I'm not sure how to recreate it. If you create a repro, that will help make it clear what the issue is.

drasticactions avatar Apr 03 '24 05:04 drasticactions

Many thanks for following up. I have updated Visual Studio to the latest version also and been using .NET 8.

So when I navigate back I get an error as follows: image

I've aimed to follow the guidance for navigation as follows: https://learn.microsoft.com/en-us/dotnet/maui/user-interface/pages/navigationpage?view=net-maui-8.0 https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/shell/navigation?view=net-maui-8.0 - and aimed to use a hierarchy as the pages are parent-child and I want to go three levels deep after the home/landing page.

I'll aim to link a repo ASAP as instructed, for the demo.

AndrewMaisey avatar Apr 03 '24 15:04 AndrewMaisey

Have popped a Git Repo here https://github.com/AndrewMaisey/NETMAUIPushPop Wondering if this is a coding issue/error or something in the platform. One thing I noticed is that I surround the code with try ... catch and hope to catch the exception but the exception seems to throw beyond the app (outside the code of the app and be handled by the runtime?).

AndrewMaisey avatar Apr 03 '24 16:04 AndrewMaisey

Verified this issue with Visual Studio for mac 17.6.11(build400) (8.0.14 & 8.0.0.-rc.2.9530). Can repro on android/iOS platforms with sample project.

kevinxufei avatar Apr 09 '24 02:04 kevinxufei

Many thanks. Are there any coding techniques that I could use so that any routing exception is picked up in a try {} catch {} block for the moment, as execution seems to be getting passed out to the runtime? Or any interim coding advice to minimise the risk of encountering a routing issue, in this context.

AndrewMaisey avatar Apr 09 '24 08:04 AndrewMaisey

You have two route registered to MainPage https://github.com/AndrewMaisey/NETMAUIPushPop/blob/main/ShellNavDemo/AppShell.xaml#L13 https://github.com/AndrewMaisey/NETMAUIPushPop/blob/main/ShellNavDemo/App.xaml.cs#L15

PureWeen avatar May 07 '24 08:05 PureWeen

Thanks, I'll take a look at removing one of these Route references. Seems like the framework added this to the root page automatically, so no need to have two.

AndrewMaisey avatar May 07 '24 08:05 AndrewMaisey

Thank you. I removed the reference from the AppShell.xaml so it looks as such:

<ShellContent Title="Home" ContentTemplate="{DataTemplate local:MainPage}" />

And left the routing as it was in the App.xaml.cs.

This works a great deal better now, thanks.

Please close the case.

AndrewMaisey avatar May 07 '24 09:05 AndrewMaisey