如何連結到 Blazor WASM 頁面的某個部分?
Documentation.razor程式碼:
@page "/documentation" .... <table class="table table-bordered"> <thead> <tr> <th>Groups</th> </tr> </thead> @foreach (var group in groups.Where(g => !string.IsNullOrEmpty(g))) { <tr><td><a href="#@gIndex">@group</a></td></tr> gIndex++; } <tr><td><a href="#@gIndex">Others...</a></td></tr> </table>
上面的程式碼建立了一個帶有超連結的群組列表,如下所示:
/#0 /#1 /#2 /#3
但是,當我點擊連結時,它們會將我路由到網頁應用程式的根目錄,而不是目前頁面的一部分,例如
/documentation#0 /documentation#1 /documentation#2 /documentation#3
如果我在瀏覽器中前往 /documentation 並手動附加這些部分,則瀏覽器會執行適當的重定向。
我嘗試像 a href="documentation#@gIndex"
這樣對路由進行硬編碼,但這沒有任何作用。
有什麼想法可以讓超連結到同一頁上的某個部分來運作嗎?
這個錯誤很久以前就被提出了,請關注這裡:哈希路由到命名元素一个>
#嘗試如下更改連結: