Not updating js module after route change
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
I am trying to load lottie animations after every click of the button. I chose to not load animation itself but rather use routing. So every click will create a route localhost/1 -> it should load 1.json (lottie animation), localhost/2 -> it should load …json etc.
The problem is that I tried to use every lifecycle and also statehaschanged but nothing helped to change the lottie animation even if parameter is passing correctly. So first change works Index->/number but after same animation is being display despite the fact the number is changing.
Could you please help me out?
Thank you.
@page "/{animNumber:int}"
@inject IJSRuntime JSRuntime
@inject NavigationManager navigationManager
<PageTitle>Index</PageTitle>
<h3>Anim @animNumber</h3>
<lottie-player src="lottie/(@animNumber).json" background="transparent" speed="1" style="width: 300px; height: 300px;" loop autoplay></lottie-player>
<audio id="roar" src="/sound/duo.mp3" @onended="NavigateToNextAnimation" />
<button id="soundButton" @onclick="PlaySound">Click me!</button>
@code {
[Parameter]
public int animNumber { get; set; }
public async Task PlaySound()
{
await JSRuntime.InvokeAsync<string>("PlayAudio", "roar");
animNumber++;
}
public void NavigateToNextAnimation()
{
navigationManager.NavigateTo($"/{animNumber}");
}
}
Expected Behavior
To change animation after every button click.
Steps To Reproduce
Minimal version: https://github.com/Laftek/BlazorNotReloadingLottie.git
Exceptions (if any)
No response
.NET Version
7.0.100
Anything else?
No response
Issue Analytics
- State:
- Created 10 months ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
React Routers Switch is not updating when the route has ...
To solve the issue, you can force re-mount on route change by passing a key prop to the Category component which changes on...
Read more >Switch not updating Route when route change occurs #130
If Switch is never re-rendered, it doesn't update which causes it to not update which Route component it should render.
Read more >How to Update the Application Title based on Routing ...
The Routing Configuration. Open the app-routing.module.ts file, and create the initial routes.
Read more >Router tutorial: tour of heroes
In this tutorial, you build upon a basic router configuration to explore features such as child routes, route parameters, lazy load NgModules, guard...
Read more >Building Isomorphic JavaScript Apps: From Concept to ...
You should be able to click through the links, see the address bar update in ... HTTP router, call, and since Browserify was...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@MackinnonBuck Thank you! it works now! Thanks again!
@Laftek If the generated HTML is correct, then this seems to be a bug in the
lottie-playercustom element, not Blazor. It’s possible that the custom element isn’t reacting to changes to its attribute values. You could try adding a@keyattribute to the custom element and setting its value toanimNumberto force the custom element to be destroyed and re-created whenanimNumberchanges.