WhileActive Trigger not working the first time a Page loads in Navigator

Hello,

I noticed that the WhileActive is not being fired for the first time when you visit a page, it starts working on the second visit.

A simple project file that can be reproduce the behavior.

MainView.ux

<App>
    <Router ux:Name="router" />
    <Navigator DefaultTemplate="Home" Background="#000000">
        <Home ux:Template="Home" router="router" />
        <Search ux:Template="Search" router="router"/>
    </Navigator>

    <Page ux:Class="Home" Background="#ffffff">
        <Router ux:Dependency="router" />

        <JavaScript>
            module.exports.Search = function() {
                router.push('Search');
            }
        </JavaScript>

        <WhileActive>
            <DebugAction Message="Home"/>
        </WhileActive>

        <Button Height="50" Width="300" Background="Black" Clicked="{Search}">
            <Text TextAlignment="Center" Alignment="Center" Color="White">Go to Search</Text>
        </Button>
    </Page>

    <Page ux:Class="Search">
        <Router ux:Dependency="router" />
        <JavaScript>
            module.exports.GoBack = function() {
                router.goBack();
            }
        </JavaScript>

        <WhileActive>
            <DebugAction Message="Search"/>
        </WhileActive>

        <Button Height="50" Width="300" Background="White" Clicked="{GoBack}">
            <Text TextAlignment="Center" Alignment="Center" Color="Black">Go back to Home Page</Text>
        </Button>
    </Page>
</App>

Any news on this?

Try to set the Bypass property of the trigger like this: <WhileActive Bypass="Never">.
By default triggers update when you transition to the state they monitor. Since this page is your DefaultTemplate it means that it is created in this state (rather than transitioning to it) and thus it won’t trigger by default.

Hmm, I would however expect that the trigger in your Search page should fire the first time you navigate to it.
Will investigate this further.

To execute actions on a page when it becomes active you should use the Activated trigger instead.

    <Activated Handler="{jsCall()}">
		<DebugAction Message="activate Search"/>
	</Activated>

This avoids subtle issues with how WhileActive in a Navigator is actually triggered.

That said, your original code does appear to exhibit a defect, even if not the intended use. I’ll look at what causes it.