找不到Blazor WASM.Net5预渲染页



我已经建立了一个基本的WASM托管模板,并已转换为以下的预渲染

https://jonhilton.net/blazor-wasm-prerendering/#commento-登录箱容器

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

一切似乎都如预期的那样工作,我可以点击导航链接,它会按预期更改页面。但是,我无法通过URL直接导航到页面。如果我在localhost:port/Counter中键入,则无法找到localhost页面。当我点击counter的导航链接时,它显示的URL为localhost:port/counter。

为什么我不能直接导航到URL?

编辑:

以下是一些文件来了解发生了什么。

这是服务器启动.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");
});
}

此处的更改是将mappfallback更改为/\uHost的文件。这是一个添加到Server/Pages文件夹的新文件,如下

@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>

在服务器启动过程中,我将回退更改为/Host

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

然而,问题是它不应该是端点。MapFallbackToFile("_Host"(;它应该是端点。MapFallbackToPage("/\uHost"(;这就是导致刷新失败的原因

最新更新