Joe*_*eyD 2 webassembly blazor .net-5
我已经设置了一个基本的 WASM 托管模板并已转换为以下预渲染
https://jonhilton.net/blazor-wasm-prerendering/#commento-login-box-container
和
https://chrissainty.com/prerendering-a-client-side-blazor-application/
一切似乎都按预期工作,我可以单击导航链接,它会按预期更改页面。但是,我无法通过 URL 直接导航到页面。如果我输入 localhost:port/Counter 我会得到一个无法找到本地主机页面。当我单击计数器的导航链接时,它显示的 URL 为 localhost:port/Counter。
为什么我无法直接导航到该 URL?
编辑:
以下是一些文件,可帮助您了解正在发生的情况。
这是服务器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");
});
}
Run Code Online (Sandbox Code Playgroud)
这里的更改是更改/_Host的mappfallbacktofile。这是添加到 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>
Run Code Online (Sandbox Code Playgroud)
在服务器启动内部,我将 Fallback 更改为 /_Host
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
//endpoints.MapFallbackToFile("index.html");
endpoints.MapFallbackToFile("/_Host");
});
Run Code Online (Sandbox Code Playgroud)
但问题是它不应该是 endpoint.MapFallbackToFile("_Host"); 它应该是endpoints.MapFallbackToPage("/_Host"); 这就是导致刷新失败的原因
| 归档时间: |
|
| 查看次数: |
557 次 |
| 最近记录: |