Here is how honkmother(https://github.com/honkmother) did it. Here is the link:
https://github.com/aspnet/Blazor/issues/842#issuecomment-490671409
The Index.cshtml:
@page "{*clientPath}"
<!DOCTYPE html>
<html>
@(await Html.RenderComponentAsync<html>())
</html>
Then two classes called "html" and "metatags".
The html class creates the html tags and store the header (script tags, etc) inside of a html file that is injected as markup.
public class html : ComponentBase
{
public static string HeadTXT = File.ReadAllText("head.htm");
Metatags meta = new Metatags() { Title = "some title" };
protected override void BuildRenderTree(Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder)
{
builder.OpenElement(0, "head");
builder.AddMarkupContent(1, HeadTXT);
builder.OpenComponent<Head>(2);
builder.AddAttribute(3, "MetaInfo", meta);
builder.CloseComponent();
builder.CloseElement();
builder.OpenElement(4, "body");
builder.OpenComponent<Body>(5);
builder.AddAttribute(6, "MetaInfo", meta);
builder.CloseComponent();
builder.AddMarkupContent(7, "<script src=\"_framework/components.server.js\"></script>");
builder.CloseElement();
}
}
public class Metatags
{
public string Title { get; set; } = "example.nyc — weirdest hack ever";
public string Description { get; set; } = "testing";
public Head Component;
}
A "body" Component.
<DetectPrerender MetaInfo="@MetaInfo">
<Router AppAssembly="typeof(Startup).Assembly" />
</DetectPrerender>
@functions {
[Parameter]
private Metatags MetaInfo { get; set; }
}
And a "head" component.
@using example.Shared
<title>@MetaInfo.Title</title>
<meta name="description" content="@MetaInfo.Description">
@{
MetaInfo.Component = this;
}
@functions {
[Parameter]
private Metatags MetaInfo { get; set; }
private bool ShouldRend = false;
protected override bool ShouldRender()
{
if (ShouldRend)
{
ShouldRend = false;
return true;
}
return false;
}
public void ShouldRe()
{
ShouldRend = true;
base.Invoke(() => base.StateHasChanged());
}
}