NavigationManager.NavigateTo in .NET MAUI Blazor Hybrid not working

260 views Asked by At

I am trying to navigate from razor page to razor page but it looks like the Blazor syntax is not working properly for NavigateTo()

@page "/"

@using System.Diagnostics;
@inject NavigationManager Navigation;

<button type="button" class="btn btn-primary" @onclick="NavigateToPage">GoTo Foopage</button>

@code {
    private async void NavigateToPage()
    {   
        Navigation.NavigateToPage("/foopage", true);
        Debug.WriteLine($"NavigateTo Foopage clicked");        
    }
}
@page "/foopage"

@using System.Diagnostics;

<h1> Foo Page</h1>

@code {
    protected override void OnInitialized()
    {   
        Debug.WriteLine($"This is the FooPage");        
    }
}
1

There are 1 answers

1
Alexandar May - MSFT On

The NavigationManager doesn't provide Navigation.NavigateToPage("/foopage", true);. You need call the NavigateTo() method to navigate to the desired URL. Please change the Navigation.NavigateToPage("/foopage", true); to Navigation.NavigateTo("/foopage", true); to get it worked like below:

private async void NavigateToPage()
{
      Navigation.NavigateTo("/foopage", true);
      Debug.WriteLine($"NavigateTo Foopage clicked");
}