繁体   English   中英

Blazor JS 路由问题,static _blazor js 未找到

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM