Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inject IUriHelper service in Blazor?

How to add implementation of IUriHelper service to Startup.cs in Blazor?

like image 717
Dmitry Avatar asked Sep 29 '19 13:09

Dmitry


1 Answers

IUriHelper is now NavigationManager. See Get current Url in a Blazor component for details.

You can inject and use NavigationManager at Shared/NavMenu.cshtml without issues. You don't need any expecial, you don't need to add NavigationManager at app startup, it's already injected. Sample:

Shared/NavMenu.cshtml:

@inject NavigationManager NavigationManager

<div class="top-row pl-4 navbar navbar-dark">
    <a class="navbar-brand" href="">
        @(NavigationManager.Uri)    @* <--- sample using it --- *@
    </a>
    <button class="navbar-toggler" @onclick="ToggleNavMenu">
        <span class="navbar-toggler-icon"></span>
    </button>
</div>

Result:

enter image description here

like image 54
dani herrera Avatar answered Nov 09 '22 05:11

dani herrera