Search code examples
blazorblazor-webassembly

Blazor WASM Head component, page source and social media share


I'm using the new <PageTitle> and <HeadContent> components in Blazor WASM .net6.

It works fine and if I look in the devtools elements everything is work like it is supposed. enter image description here

But if I look at page source none of these things are not shown, even though in Program.cs it is supposed to add it to the html head. enter image description here

This creates a problem when I try to share to social media platforms since they depend on the information in the tag for the page source.

What would be the best way to solve this?


Solution

  • This is a basic property of Blazor WebAssembly (and all other SPA frameworks): The final HTML page is 'constructed' inside the client. View-Source only shows the initial loader page.

    Options:

    1. Embed the information in the index.html page. The sample you showed looks like it only contains fairly static information. Not clear without the .razor source though.

    2. Use server pre-rendering. That requires hosting on asp.net with razor pages enabled.