[英]Blazor JS routing problem, static _blazor js not found
我有一個 asp.net 6 應用程序,我正在嘗試向其中添加服務器端 blazor 組件。 我有我的程序設置,我正在調用我的組件,但是當我導航到頁面時它找不到 static blazor 文件,因為它放入了路由中。 我該如何解決這個問題?
此外,我可以讓 static 和 ServerPrerendered 渲染模式正常工作,而不是服務器,因為它需要 JS。
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddHttpContextAccessor();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
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.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.MapBlazorHub();
app.Run();
_Layout.cshtml
<script src="~/_framework/blazor.server.js"></script>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
搜索組件調用:
<component type=typeof(ItemSearch) param-Search=Model.Search render-mode=Server />
在我的索引頁面上:
Information: Normalizing '_blazor' to 'https://localhost:7216/_blazor'.
一旦我搜索:
https://localhost:7216/Search/_blazor/initializers 404
解決方案是在頭部添加鹼基。 _layout.cshtml 的
<head>
<base href="~/"/>
</head>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.