mcfoi
mcfoi

Reputation: 114

.NET MAUI ApplyQueryAttributes being called even navigating back from unrelated pages

I implemented a simple Shell navigation (pseudocode):

Home -> GoToAsync Page1 -> GoToAsync Page2 -> backward navigate to Home using GoToAsync("../../")

In the last step I am passing parameters collected in Page1 and Page2 so that method ApplyQueryAttributes() in Home executes for the FIRST TIME and I can retrieve them.

From that moment the user can move along a different path:

Home -> GoToAsync Page3

The fact is: when navigating back from Page3 to Home using backbutton or default 'go-back' arrow in AppTitle, the method ApplyQueryAttributes() in Home ALWAYS executes and ALWAYS receives the parametes it hot from Page2

Is this a BUG or a FEATURE?

In my opinion is a BUG since nothing is pushing to Home those parameters when moving from Page3 to Home. It is like the "back to home" route gets cached and when traveling that way, the "cached" route (with is parameter) gets executed.

Is there any way to prevent this behaviour? (whatever it is, a bug or a feature)

Upvotes: 3

Views: 1716

Answers (1)

Haimo
Haimo

Reputation: 151

I got the same issue but found a kind of work around. It does not prevent the misbehavior but the back-parameters are ignored:

Every Page has this methode in order to handle back-parameters. At the end of it query is cleared and can't do any harm in other pages.

public async void ApplyQueryAttributes(IDictionary<string, object> query)
{
    if (query.Count > 0) 
    {
        // extract parameters
    }

    query.Clear(); // important
}

Upvotes: 8

Related Questions