fluentcms / FluentCMS

ASP.NET Core Blazor Content Management System (CMS)
https://fluentcms.com
MIT License
180 stars 32 forks source link

Issue on using external JS file #1293

Closed pournasserian closed 5 months ago

pournasserian commented 5 months ago

Assume that I have a JavaScript file in wwwroot: test.js

<script>
    alert('loaded')
</script>

If I add the below tag in HTML head or body section, it won't working as expected. In SSR mode, it is fine. But, routing between interactive pages, it won't work.

If we refresh an interactive page, SSR will be loaded first. So, it will work.

This is similar question: https://stackoverflow.com/questions/77541705/embed-javascript-in-the-blazor-component-in-net-8

pournasserian commented 5 months ago

@babakhani the new layout implementation is depended to this

ParsaGachkar commented 5 months ago

@pournasserian I think the PageScript component from this example is useful in this case.

https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/static-server-rendering?view=aspnetcore-8.0 https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/startup?view=aspnetcore-8.0#javascript-initializers

Blazor does not have this component by default but there is a detailed guide in documentation that addresses the issue and implements this solution.

pournasserian commented 5 months ago

@pournasserian I think the PageScript component from this example is useful in this case.

https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/static-server-rendering?view=aspnetcore-8.0 https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/startup?view=aspnetcore-8.0#javascript-initializers

Blazor does not have this component by default but there is a detailed guide in documentation that addresses the issue and implements this solution.

Correct, it says:

When using Blazor's enhanced navigation feature, which allows the user to avoid reloading the entire page, page-specific JS may not be executed again as expected each time an enhanced page navigation occurs.

And then:

To avoid this problem, we don't recommended relying on page-specific Githubissues.

  • Githubissues is a development platform for aggregating issues.