Reputation: 225
I'm using Blazor Server for website with paginated list with listings/search results (as in any normal online directory website). I'm wondering what's the best fix for the scenario below:
I have a Search component which takes category name as parameter plus Query String so the url can look like this https://example.com/cars?loc=london?text=silver
It can give me more than 10 results so I added pagination.
When I go to next page the url will add page number e.g https://example.com/cars?loc=london?text=silver?page=3
My problem is that when I go to the component for the first time it executes OnInitializedAsync() and OnParametersSetAsync() as expected.
When I click on the next/previous page number I have the code below but the Navigation manager is not calling the OnInitializedAsync() and OnParametersSetAsync() methods again so I can't get the new list based on page number (I can only see the page number in url but nothing happens).
Can I force Blazor to run OnInitializedAsync() and OnParametersSetAsync() again or am I doing it wrong?
public void PageIndexChanged(int newPageNumber)
{
if (newPageNumber < 1 || newPageNumber > totalPages)
{
return;
}
currentPage = newPageNumber;
//...
query.Add("page", currentPage.ToString());
NavigationManager.NavigateTo(QueryHelpers.AddQueryString(categoryUrl, query));
}
Upvotes: 0
Views: 1889
Reputation: 575
Hy ,
This is a longshot, butt did you try ;
navigationManager.NavigateTo(url,true)
The true at the end forces the navigation manager to (re)load the page.
regards,
Upvotes: 1