Blazor JS路由问题,找不到静态_blazor js

JBu*_*son 5 c# asp.net-core blazor

我有一个 asp.net 6 应用程序,我正在尝试添加服务器端 blazor 组件。我已经设置了程序,正在调用我的组件,但是当我导航到该页面时,它无法找到静态 blazor 文件,因为它放入了路由中。我该如何解决这个问题?

另外,我可以让静态和 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();
Run Code Online (Sandbox Code Playgroud)

_布局.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)
Run Code Online (Sandbox Code Playgroud)

搜索组件调用:

<component type=typeof(ItemSearch) param-Search=Model.Search render-mode=Server />
Run Code Online (Sandbox Code Playgroud)

在我的索引页上:

Information: Normalizing '_blazor' to 'https://localhost:7216/_blazor'.
Run Code Online (Sandbox Code Playgroud)

一旦我搜索:

https://localhost:7216/Search/_blazor/initializers 404 
Run Code Online (Sandbox Code Playgroud)

JBu*_*son 9

解决办法是在头部添加碱。_layout.cshtml 的

<head>
    <base href="~/"/> 
</head>
Run Code Online (Sandbox Code Playgroud)