Maui сhange navigation in BlazorWebView

Occasional Visitor

How can I change a page in BlazorWebView using Maui? For example, the page '/' was opened and I need to open '/fetch'.

I found how to return to the previous link via js.

Created a Custom Navigation Manager:


public class CustomNavigationManager
private static IJSRuntime JSRuntime { get; set; }
public CustomNavigationManager(IJSRuntime jSRuntime)
    JSRuntime = jSRuntime;

public static async Task Navigation(string url)
if (JSRuntime!= null)
await JSRuntime.InvokeVoidAsync("navigation", url);



Which calls the Js code. Which calls the Js code. Which I placed in wwwroot/index.html


<script type="text/javascript">
    window.navigation = (url) => {
    window.location.href = url; // Error: There is no content at fetch.
    //window.location=""; //Error: There is no content at fetch.


Registering a service




And inject in Shared/MainLayout.razor


@page "/"
@inject CustomNavigationManager navigation


And I use it in maui


await CustomNavigationManager.Navigation("/fetch");


If I use the js code ```history.back();``` then everything works,

but if I want to redirect to /fetch using


window.location.href = url;



then I get an error: There is no content at fetch.

Fetch.razor page


@page "/fetch"
@page "/fetch/{id}"




1 Reply

Hi @Denis_Polagaev,

Thanks for posting your issue here.

However this platform is used for how-to discussions and sharing best practices for building any app with .NET.Since your issue is a technical question, welcome to post it in Microsoft Q&A forum, the support team and communities on Microsoft Q&A will help you for any technical questions.
Besides, it will be appreciated if you can share it here once you post this technical question Microsoft Q&A.
Best Regards,
Lan Huang