6

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

Dmitry
  • 549
  • 1
  • 5
  • 16

2 Answers2

20

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

dani herrera
  • 48,760
  • 8
  • 117
  • 177
-2

You don't have to, it is injected by default.

Flores
  • 8,226
  • 5
  • 49
  • 81