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