簡體   English   中英

Blazor razor 頁面中的 WASM 自定義元素僅適用於根 (Index.cshtml) 頁面

[英]Blazor WASM custom elements in razor pages only working on the root (Index.cshtml) page

我修改了這個 Blazor 自定義元素示例(“.NET 7 Blazor 自定義元素示例托管在 ASP.NET 核心 Razor 頁面”: https://github.com/khalidabuhakmeh/BlazorCustomElementsSample )以顯示問題。 我還將項目更新為當前的 .NET 7,並且還刪除了不再需要的<script src="_content/Microsoft.AspNetCore.Components.CustomElements/BlazorCustomElements.js"></script>

當您運行更新的項目時可以驗證問題,我將自定義元素添加到其他頁面: https://github.com/horacioj/BlazorCustomElementsSample

當您將自定義元素添加到/privacy/some/routed/page時,自定義元素<my-counter title="Khalid" increment-amount="2" />不起作用。

/privacy頁面,問題是: GET https://localhost:7213/Privacy/_content/Microsoft.AspNetCore.Components.CustomElements/Microsoft.AspNetCore.Components.CustomElements.lib.module.js.net::ERR_ABORTED 404

/some/routed/page頁面,問題是: blazor.webassembly.js: GET https://localhost:7213/some/routed/_framework/blazor.boot.json 404

我不知道如何解決這個問題。

參考: Blazor 自定義元素https://learn.microsoft.com/en-us/as.net/core/blazor/components/?view=as.netcore-7.0#blazor-custom-elements

謝謝

編輯:值得注意的是,當從BlazorSolo.Components.csproj中刪除<PackageReference Include="Microsoft.AspNetCore.Components.CustomElements" Version="7.0.1" />時,實例化 Blazor 組件的舊方法( <component type="typeof(Counter)" param-title="@("the title")" param-IncrementAmount="3" render-mode="WebAssemblyPrerendered" /> ) 在任何頁面上都能正常工作。

如果保留Microsoft.AspNetCore.Components.CustomElements package, <component...>也會失敗,在 JS 控制台中出現相同的錯誤,即使在刪除對builder.RootComponents.RegisterCustomElement<Counter>("my-counter"); <my-counter title="routed page" increment-amount="2" />

這可能是Microsoft.AspNetCore.Components.CustomElements中的錯誤嗎?

參考 https://github.com/do.net/as.netcore/issues/45818

https://github.com/mkArtakMSFT說:

您在索引中缺少一行來注冊應用程序的基本路徑。 即,將<base href="/" />添加到 Layout.cshtml 文件的頭部部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM