如何链接到 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"
这样对路由进行硬编码,但这没有任何作用。
有什么想法可以让超链接到同一页面上的某个部分来工作吗?
这个错误很久以前就被提出了,请关注这里:哈希路由到命名元素一个>
尝试按如下方式更改链接: