织梦CMS - 轻松建站从此开始!

欧博ABG官网-欧博官方网址-会员登入

How to prevent defaDG游戏ult navigation for Blazor N

时间:2025-09-07 22:49来源: 作者:admin 点击: 7 次
Although the net result of the HTML <A> tag and the Blazor NavLink component is the roughly the same thing, the @onclick:preventDefault syntax o

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.

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2025-09-14 06:09 最后登录:2025-09-14 06:09
栏目列表
推荐内容