In the Blazer Server Side project with .NET 6, I am on the following page:
https: //localhost: 7252/Product/a3620f82-7cba-473c-9273-1cf300a181eb
I have a NavLink on this page that points to the exact same URL above. But when I click on the method, the page does not show any reaction and does not refresh or update. What should I do?
Sample my codes:
@page "/Product/{Id:guid}"
@using Application.ProductGalleries.Queries
@using Application.Products.Queries
@using ViewModels.ProductVariants
@using ViewModels.ProductVariantsDetails
@using ViewModels.Products
<div class="col-12 px-0">
<h1>
<NavLink href="@($"/Product/a3620f82-7cba-473c-9273-1cf300a181eb")">@Model.ProductName</NavLink>
</h1>
<p>دسته بندی : @Model.CategoryName<span> برند: @Model.BrandName</span></p>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><NavLink href="/">صفحه نخست</NavLink></li>
<li class="breadcrumb-item"><NavLink href="/Products">@Model.CategoryName</NavLink></li>
<li class="breadcrumb-item active" aria-current="page">@Model.BrandName</li>
</ol>
</nav>
</div>
@code {
[Parameter]
public Guid Id { get; set; }
protected override Task OnParametersSetAsync()
{
return base.OnParametersSetAsync();
}
protected override Task OnAfterRenderAsync(bool firstRender)
{
return base.OnAfterRenderAsync(firstRender);
}
protected override bool ShouldRender()
{
return base.ShouldRender();
}
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
}
protected override void OnInitialized()
{
base.OnInitialized();
}
protected override void OnParametersSet()
{
base.OnParametersSet();
}
public override Task SetParametersAsync(ParameterView parameters)
{
return base.SetParametersAsync(parameters);
}
protected async override Task OnInitializedAsync()
{
var request = new GetProductByIdQuery() { ProductId = Id };
var product = await Mediator.Send(request: request);
if (product.Value != null)
{
Model = product.Value;
GalleryModel = await GetGallery();
}
}
}
During the search, if the user has searched for bananas and is on the search page and wants to search for bananas again, the page will not show any reaction. I went through all the life cycle overrides to see where it was going but it didn't react.
I also thought of using StateHasChanged (). But my code is a NavLink and where should I put this code when the project does not enter the life cycle?
You actually need to NavigateTo your current Uri with force load. I use simple extension method for this
public static void ReloadPage(this NavigationManager manager)
{
manager.NavigateTo(manager.Uri, true);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With