Keen and Blazor Enhanced Navigation and
Blazor 8 comes with a feature "Enhanced navigation" which basically intercepts navigation using anchor elements and instead of a full page load, issues a fetch request with subsequent DOM diff/patch.
Blazor supports registering an event listener for that scenario which I have currently implemented as follows:
Blazor.addEventListener("enhancedload", () => {
KTComponents.init();
}); This appears to work even though it registers a ton of redundant event handlers. Especially on the body element (which I have fixed locally by creating a special eventId in util.js for the body case and checking window.KTUtilDelegatedEventHandlers for duplicates prior to registering the handlers).
Is anything else missing?
Replies (3)
Hi,
From your post, it looks like you are trying to change our Blazor initialization flow.
Currently, we trigger initialization functions from the OnAfterRender event.
Here's an example:
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
JS.InvokeVoidAsync("KTComponents.init");
}
} You can find full global initialization code in Starterkit/Shared/MasterInit.razor.
You can find the complete global initialization code in Starterkit/Shared/MasterInit.razor. If you're considering a different approach for initialization, you need to ensure that your function is triggered after the DOM elements are rendered.
Does your current code cause any errors?
Regards,
Lauris Stepanovs,
Keenthemes Support Team
Hi Oliver,
Thank you for the suggestion. We will check this initialization approach and consider implementing it for future releases.
In our current version, we handle Javascript initialization through JS interop.
Regards,
Lauris Stepanovs,
Keenthemes Support Team