Blazor WASM .Net5 Prerender Page Cannot Be Found

Viewed 412

I have set up a basic WASM Hosted template and have converted to a Prerendered following

https://jonhilton.net/blazor-wasm-prerendering/#commento-login-box-container

and

https://chrissainty.com/prerendering-a-client-side-blazor-application/

All seems to work as expected, I can click on the nav links and it changes pages as expected. However, I cannot directly navigate to a page via URL. If i type in localhost:port/Counter i get a Localhost page cannot be found. When I click the navlink for counter it shows the URL as localhost:port/Counter.

Why am I not able to directly navigate to the URL?

EDITED:

Here are some of the files to get an idea of whats going on.

Here is the Server Startup.cs

public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {

            services.AddControllersWithViews();
            services.AddRazorPages();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebAssemblyDebugging();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseBlazorFrameworkFiles();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
                //endpoints.MapFallbackToFile("index.html");
                endpoints.MapFallbackToFile("/_Host");
            });
        }

The changes here was to change the mappfallbacktofile of /_Host. This was a new file added to the Server/Pages folder and is as follows

@page "/"
@using BlazorAppNet5WasmHosted.Client
@namespace BlazorAppNet5WasmHosted.Server.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<!DOCTYPE html>
    <html>

    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
        <title>BlazorAppNet5WasmHosted</title>
        <base href="/" />
        <link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
        <link href="css/app.css" rel="stylesheet" />
        <link href="BlazorAppNet5WasmHosted.Client.styles.css" rel="stylesheet" />
    </head>

    <body>
        <component type="typeof(App)" render-mode="WebAssemblyPrerendered" />
        <script src="_framework/blazor.webassembly.js"></script>
    </body>

</html>
1 Answers

Inside the server startup i had which change the Fallback to /_Host

app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
                //endpoints.MapFallbackToFile("index.html");
                endpoints.MapFallbackToFile("/_Host");
            });

However the issue is it should not be endpoint.MapFallbackToFile("_Host"); it should be endpoints.MapFallbackToPage("/_Host"); That is was what causing the refresh to fail

Related