You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Goal: Set meta tags (title, description etc) for SEO and Open Graph purposes with data coming from the page itself. Using the Javascript interop won't help as pages won't be able to be crawled.
I have used a suggestion by @Honkmother and moved the base component further up the tree to encapsulate the <html> tag but for some reason this has affected routing. All links are prepended with ~/ and I can't seem to understand why.
I have created an example repo here if anyone is intersted in taking a look.
<div id="blazor-error-ui">
<environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded.
</environment>
<environment include="Development">
An unhandled exception has occurred. See browser dev tools for details.
</environment>
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
AppState.cs
using System;
namespace BlazorMetaTags
{
public class AppState
{
public MetaTags MetaTags { get; private set; } = new MetaTags();
public event Action OnChange;
public void SetMetaTags(MetaTags metatags)
{
MetaTags = metatags;
NotifyStateChanged();
}
private void NotifyStateChanged() => OnChange?.Invoke();
}
}
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddScoped<AppState>();
services.AddSingleton<WeatherForecastService>();
}
The text was updated successfully, but these errors were encountered:
@thewebchameleon I'm not sure rendering the script tag from a component is going to work. It's required to bootstrap Blazor Server. That said, as you pointed out, the linked issue - #10450 - already tracks the work to be done here. If you need specific help using using Blazor, please use StackOverflow with the asp.net-core-blazor tag.
This is in reference to #10450.
Goal: Set meta tags (title, description etc) for SEO and Open Graph purposes with data coming from the page itself. Using the Javascript interop won't help as pages won't be able to be crawled.
I have used a suggestion by @Honkmother and moved the base component further up the tree to encapsulate the
<html>
tag but for some reason this has affected routing. All links are prepended with~/
and I can't seem to understand why.I have created an example repo here if anyone is intersted in taking a look.
_Hosts.cshtml
AppBase.cs
Head.razor component to set the meta tags
Body.razor
AppState.cs
Startup.cs
The text was updated successfully, but these errors were encountered: