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");
}
}
The NavigationManager doesn't provide
Navigation.NavigateToPage("/foopage", true);
. You need call theNavigateTo()
method to navigate to the desired URL. Please change theNavigation.NavigateToPage("/foopage", true);
toNavigation.NavigateTo("/foopage", true);
to get it worked like below: