I have a Blazor
(web-assembly
) page that has a map(Leaflet
) which is heavily loaded items on it. When user moves to another page then returns to the map page(with routing not reloading) the map div
element cleared and I have to fill the map again with the items. Is it possible to somehow keep those items on the map(memory) so no redrawing is needed when the user comes back to the MapPage
?
current scenario:
- User goes to MapPage
- So many items loaded on the map via javascript call in
OnAfterRenderAsync
method - user goes to another page
- user comes back to MapPage
- MapPage component is
cleared
now and should be rendered again - page will be rendered again So many items loaded again on the map(step 2)
what I want :
- User goes to MapPage
- So many items loaded on the map via javascript call in OnAfterRenderAsync method
- user goes to another page
- user comes back to MapPage
- MapPage will be loaded from memory and everything from step 2
here is my MapPage code :
protected async override Task OnAfterRenderAsync(bool firstRender)
{
await js.InvokeVoidAsync("showMapItems");
await base.OnAfterRenderAsync(firstRender);
}
Update (for bounty): Suppose that the page is loading locations and show them on the map. If user clicks on the each location he should be redirected to a detail page and the he will go back to search page.
Hacky solution : I decided to hide the map by setting its display:none
and show the detail component. But I want detail to be also accessible through URL, and when user clicks on detail on the map the URL should be changed. So I used the following route but I get an error while loading the page :
@page "/location/search"
@page "/location/search#{LocationId:int}"
@code{
[Parameter] public string LocationId { get; set; }
}
and I get the following error in browser:
Invalid template 'location/search#{*LocationId}'. Missing '{' in parameter segment 'search#{*LocationId}'.