简体   繁体   中英

Blazor JS routing problem, static _blazor js not found

I have a asp.net 6 application I am trying to add a server side blazor component to. I have my program setup, I am calling my component but when I navigate to the page it cant find the static blazor file because its putting in the routing. How do I resolve this?

Also I can get static and ServerPrerendered render modes to work correctly just not Server as it requires the 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)

Search Component Call:

<component type=typeof(ItemSearch) param-Search=Model.Search render-mode=Server />

On my index page:

Information: Normalizing '_blazor' to 'https://localhost:7216/_blazor'.

Once I search:

https://localhost:7216/Search/_blazor/initializers 404 

The solution is add base to the head. of _layout.cshtml

<head>
    <base href="~/"/> 
</head>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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