New Metronic Docs!Added Integration Docs with Starter Kits Apps for Laravel, Laravel Livewire, Angular, Vue, Symfony, Blazor Server, Django & Flask & more
Browse Docs

Metronic v9 for Blazor


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?


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (8)


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>


Make your image paths are correct. In the starter kit, images should be in wwwroot/assets/media/ and referenced with paths starting with /assets/media/ or assets/media/ (without leading slash works in Blazor).

Check your image references. In Sidebar.razor, images are referenced like: src="assets/media/app/default-logo.svg"
Ensure you copied the media folder from metronic/dist/ to wwwroot/assets/ as per the README.



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?


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(