Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Why is OnInitialized triggered when using NavigationManager to navigate to the same page

$
0
0

This is in a Blazor Server App with per page interactivity.

In my search page, I want to update the page url when the parameter changes, so the link can be copied. My understanding was that by using the NavigationManager Blazor would detect no full reload is needed, and skip component initialization.

I would expect the following code not to hit OnInitialized() after Start search is clicked.

    @page "/test/{searchvalue}"    @rendermode InteractiveServer    @inject NavigationManager _NavigationManager<InputText @bind-Value="SearchInput"></InputText><div @onclick="(() => Search())">Start search</div><br /><br />    Test input: @SearchValue    @code{        [Parameter]        public string SearchValue { get; set; } = "";        public string SearchInput { get; set; } = "";        protected override void OnInitialized()        {            // Inital filter settings etc.            // ...            base.OnInitialized();        }        protected override void OnParametersSet()        {            SearchInput = SearchValue;        }        protected void Search()        {            _NavigationManager.NavigateTo($"/test/{SearchInput}", false, false);        }    }

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>