Skip to content

This sample code describe that how to enable server-side rendering on a client-side blazor application.

License

Notifications You must be signed in to change notification settings

sample-by-jsakamoto/Blazor-ClientSideBlazorSSR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sample Code: How to enable Server-Side Rendering on Client-Side Blazor App?

Summary

This sample code describes that how to enable server-side rendering on a client-side blazor application.

Pre required

  • .NET 5.0 SDK
  • A Client-Side Blazor application with ASP.NET Core hosted project.

Migration Step

  1. Remove "index.html" from the client project, and add "_Host.cshtml" Razor Page file to the server project, instead.
    The contents of "_Host.cshtml" is almost a copy of "index.html", however, it has server-side rendering instruction in the <app> element.
<app>
  ...
  <component type="typeof(App)" render-mode="Static" />
  1. Add Razor Pages feature to the server at server-side Startup class, and change the fallback page specification to the URL of "_Host.razor" Razor Page.
public class Startup
{
  public void ConfigureServices(IServiceCollection services)
  {
    services.AddRazorPages();
    ...
  }

  public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  {
    ...
    app.UseEndpoints(endpoints =>
    {
      ...
      endpoints.MapFallbackToPage("/_Host");
    });
    ...

That's all!

Appendix

However, the HttpClient dependency injection at Blazor components might be failed when it's rendering in server-side.

Therefore, those Blazor components such as Fetch.razor have to change that implementation.

You can see one of the examples ways at the commit 18298a37.

License

This sample code provides under The Unlicense.

About

This sample code describe that how to enable server-side rendering on a client-side blazor application.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published