I'm new to Blazor and I am working on an example app (Blazing Pizza) in the blazor-workshop on GitHub. In one step of the tutorial, a button is used to go to another page
<button href="checkout">Order</button>
This wasn't working so I tried to change from a button to an anchor, which did work:
<a href="checkout">Order</a>
The blazor is running client side.
Can anyone explain why the button did not work, but the anchor did? I'm also new to HTML so it could be something quite basic.
Take a look at the <button>
documentation. href
isn't a valid attribute for it. Generally, button
elements are used to submit a form or have an Event Handler attached to them to "do the thing" when they are clicked.
The standard "click to go elsewhere", as you've discovered, is the <a>
anchor element, which does natively support the href
attribute.
You can't just stick any attribute in any element and except it to behave the same by default. For styling purposes, you'll need to use some CSS to get your link to look more like a button. This is also intrinsic to HTML in general, and doesn't really have anything to do with blazor.