The ThemeForest listing for Metronic seems very deceiving. It mentions Blazor Server in the supported platforms, but the only Blazor option is if you manually download v8 using instructions from downloading v9. When will Metronic have a Blazor version in v9?
Blazor Server uses SignalR and performs partial DOM updates, which means JavaScript components need to be reinitialized after each navigation. Additionally, image paths may need adjustment for Blazor's routing structure.
The navigation menu (KTMenu) needs to be reinitialized after each Blazor navigation. You need to add JavaScript initialization code that runs after Blazor completes its page updates.
Add this script directly in Components/App.razor. Place it after the Blazor script but before the closing </body> tag:
<script>
// Reinitialize Metronic components after Blazor Server navigation
(function() {
// Initialize on page load
function initMetronic() {
if (typeof KTComponent !== "undefined") {
KTComponent.init();
}
if (typeof KTLayout !== "undefined") {
KTLayout.init();
}
}
// Initialize on DOM ready
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", initMetronic);
} else {
initMetronic();
}
// Watch for Blazor Server navigation via MutationObserver
// Blazor Server updates the DOM via SignalR, so we observe those changes
let initTimeout;
const observer = new MutationObserver(function(mutations) {
// Debounce to avoid excessive initialization
clearTimeout(initTimeout);
initTimeout = setTimeout(function() {
// Check if the main content area changed
const contentChanged = mutations.some(function(mutation) {
return mutation.target.id === "content" ||
mutation.target.closest("#content") !== null;
});
if (contentChanged) {
initMetronic();
}
}, 150);
});
// Observe the main content area for changes
const contentArea = document.getElementById("content");
if (contentArea) {
observer.observe(contentArea, {
childList: true,
subtree: true
});
}
})();
</script>Awsome!! I'll take a look. Thank you Sean!
Hi,
For v9 we have Blazor Server integration guide as you can check it here:
https://keenthemes.com/metronic/tailwind/docs/getting-started/integration/blazor-server
You can also use the starterkit app for Blazor Server:
https://github.com/keenthemes/metronic-tailwind-html-integration
Regards,
Sean
In the readme step 1 is to copy the entire 'metronic-tailwind-html' folder and paste it into the root directory of your Blazor app. Where is this 'metronic-tailwind-html' folder? I downloaded the latest version of Metronic (9.2.5) and there's no folder in that package with that name. I would include a screenshot, but this editor doesn't allow me to.
Hi,
Sorry for the late reply.
In the "metronic-tailwind-html" folder please get the actual demo from dist/demo1 etc folder. The HTML templates are set per demo under "dist" folder.
Regards,
Sean
In step 2, it says to copy the "media" folder from "metronic/dist" and paste it into the "wwwroot/assets" directory. so only the media folder INSIDE the assets folder from demo1 and not the entire assets folder?
Also, the file for step 3 doesn't exist.
Hi Keith,
Apologies for the late reply.
Yes only madia folder should be there initially, CSS and JavaScript files will be added after you execute npm run build command.
Regards,
Lauris Stepanovs,
Keenthemes Support Team
Thank you, @Lauris, for the reply. I was able to run npm run build and it did create the assets folder with css, js, and vendor folders. I ran the project and the navigation menu doesn't work and some of the images seem to be missing. Is there by chance a pre-compiled version of this working?