Asked by:
blazor server | Anchor links not working anymore, after adding this code:

Question
-
User2110873642 posted
i have a component. its goal is to record webtraffic. like how the google analytics interceptor works.
but unfortunately, it has a annoying side effect. when i add the component to a page (to record it), all anchor links on that page dont work anymore.
recorder.razor
@inject Microsoft.AspNetCore.Http.IHttpContextAccessor httpContextAccessor @inject NavigationManager NavigationManager @implements IDisposable @code{ protected override void OnInitialized() { // Subscribe to the event NavigationManager.LocationChanged += LocationChanged; base.OnInitialized(); } void LocationChanged(object sender, Microsoft.AspNetCore.Components.Routing.LocationChangedEventArgs e) { string navigationMethod = e.IsNavigationIntercepted ? "HTML" : "code"; System.Diagnostics.Debug.WriteLine($"Notified of navigation via {navigationMethod} to {e.Location}"); Fazili.Logging.Api.LogPageView(httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(), NavigationManager.Uri); } void IDisposable.Dispose() { // Unsubscribe from the event when our component is disposed NavigationManager.LocationChanged -= LocationChanged; } protected override void OnAfterRender(bool firstRender) { if (firstRender) { Fazili.Logging.Api.LogPageView(httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(), NavigationManager.Uri); } } }
So when i use it on a page
@page "/test" //so when i add this component: <Fazili.Logging.Components.Recorder /> //This anchor link does not work anymore: <a href="/GoSomewhere">go</a>
Monday, August 10, 2020 3:49 AM
All replies
-
User475983607 posted
I built a test without the Fazili.Logging.Api.LogPageView() and the navigation works as expected. I cannot test Fazili.Logging.Api.LogPageView() as you did not provide the source code but I assume there is a bug somewhere. Please use the Visual Studio debugger to troubleshoot your code.
Tuesday, August 11, 2020 1:00 AM -
User2110873642 posted
i tried to reproduce it just now, and it does reproduce only if you nest a few components into each other. then place the recorder in the layout root component.
Tuesday, August 11, 2020 1:03 AM -
User2110873642 posted
my work around for this, is now to temporarely not place it in the layout page, which is not desirable.
when published on IIS, even this aprouch stops anchor links from working.
Tuesday, August 11, 2020 1:04 AM -
User2110873642 posted
but on the side of this, what would your approuch be to record it navigation?
on firstrender, + onparameterchangedasync?
Tuesday, August 11, 2020 1:05 AM