How to disable Blazor server side pre-render?
Asked Answered
D

2

6

To disable server side pre-render on asp.net core preview 3, you just needed to comment @(await Html.RenderComponentAsync<MyApp>()).

Since asp.net core preview 4, when you comment this line, the page doesn't render and on the main component @page "/", the tag <app> remains blank.

So, how can we disable server side pre-render ?

Decennary answered 19/4, 2019 at 15:28 Comment(0)
C
2

Finally found a solution by cores-system in github Source: https://github.com/aspnet/AspNetCore/issues/9584#issuecomment-485257261

app.UseEndpoints(endpoints =>
{
   endpoints.MapBlazorHub().AddComponent<App>(selector: "app");
   endpoints.MapFallbackToFile("index.html"); // or - endpoints.MapFallbackToPage("/_Host");
});

Hope this works...

Crispation answered 21/4, 2019 at 17:21 Comment(1)
Additional informations: 1) Add the index.html inside wwwroot folder 2) Remover <base href="~/" /> from the htmlDecennary
D
5

According to MS Docs: https://learn.microsoft.com/en-us/aspnet/core/blazor/state-management?view=aspnetcore-6.0&pivots=server#handle-prerendering

To disable prerendering, open the Pages/_Host.cshtml file and change the render-mode attribute of the Component Tag Helper to Server: CSHTML

<component type="typeof(App)" render-mode="Server" />

Prerendering of content is disabled in Pages/_Layout.cshtml: CSHTML

<component type="typeof(HeadOutlet)" render-mode="Server" />
Domela answered 9/11, 2021 at 13:52 Comment(2)
I may be outdated on the matter, but I don't seem to have the <component> stuff in my Blazor app? I guess this was back in .net 6, since things have changed a update might be niceManzanilla
@ChristopherBonitz, it does seem different in .Net 8, you have to change the <Routes> tag (Components/App.razor) learn.microsoft.com/en-us/aspnet/core/blazor/…Domela
C
2

Finally found a solution by cores-system in github Source: https://github.com/aspnet/AspNetCore/issues/9584#issuecomment-485257261

app.UseEndpoints(endpoints =>
{
   endpoints.MapBlazorHub().AddComponent<App>(selector: "app");
   endpoints.MapFallbackToFile("index.html"); // or - endpoints.MapFallbackToPage("/_Host");
});

Hope this works...

Crispation answered 21/4, 2019 at 17:21 Comment(1)
Additional informations: 1) Add the index.html inside wwwroot folder 2) Remover <base href="~/" /> from the htmlDecennary

© 2022 - 2024 — McMap. All rights reserved.