Although the net result of the HTML <A> tag and the Blazor NavLink component is the roughly the same thing, the @onclick:preventDefault syntax only works for the HTML version, not on Blazor components. Steve Sanderson : I'm afraid there isn't a mechanism for passing through arbitrary directive attributes such as @*:preventDefault as component parameters, so this isn't expected to work on NavLink. Steve also gives a possible solution: However, you could inherit your own subclass from NavLink that adds the "prevent default" behavior. For example, create NavLinkPreventDefault.razor, containing this: @inherits NavLink <a @attributes="@AdditionalAttributes" @onclick:preventDefault> @ChildContent </a>Now you can use instead of to get the behavior you want. (责任编辑:) |