You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the benefit of having a button element to navigate, rather than a proper link/anchor? I'd see more benefit to have a link to appear as a button, but just with style. See https://github.com/vaadin/vaadin-lumo-styles/issues/5
What is the benefit of having a button element to navigate, rather than a proper link/anchor? I'd see more benefit to have a link to appear as a button, but just with style. See vaadin/vaadin-lumo-styles#5
Some people want a button to look like a link with a theme variant, some people want a link to look like a button with a theme variant... 😃
Currently the RouterLink AKA <a router-link> does have some special magic that makes it a special link which blocks the default event handling for the browser. My understanding is that a RouterButton should be either a NativeButton or Button (the Vaadin one) that works 1-1 the same as the RouterLink in terms of updating the URL and making the server side routing things happen. I would probably even remove the click listener API from it, since it doesn't that much sense when it is used as router link.
The vaadin-button web component will never know anything about the routerlink features in Flow, so I would imagine having just a link that looks like a button is not enough, as you would also want to apply the router-link attribute to it if you want to use it for Flow routing. And thus it would be easiest to either
a)
Make RouterButton extends Composite<Button> (or extends Button) which adds the magical router-link attribute
Make Flow client side handle the click events from those buttons like the router links.
b)
Make it somehow possible to have an anchor that is themeable as the vaadin-button, and just add that as RouterButton extends RouterLink
a) is probably possible without client side changes to Flow, by just having a click listener on server side that triggers the navigation. I'm not sure though everything works the same as with a router link, like postponing navigation, but might be close enough.
I strongly discourage using anything other than anchors (i.e. <a href>) for navigation: anchors let the browser know what they do and are accessible like @knoobie pointed out.
The fact that anchors with the router-link attribute have the default behavior prevented to allow in-app navigation is an implementation detail that in my opinion should not justify wrong semantics.
I understand there are users coming from past Vaadin versions where navigation was done with buttons and want their app to look alike, but then I'd go with @pleku's (b) solution, i.e. styling the anchor.
Closing as not planned: a button whose click listener calls UI.navigate(...) already gives the same result, including navigation lifecycle events such as postponing in BeforeLeaveObserver. For navigation that should behave as a real link (open in new tab, accessibility), use RouterLink and style it as needed.
Activity
gilberto-torrezan commentedon Aug 24, 2017
Would it be possible to have a generic API that could be used for any kind of button (VaadinButton, PaperButton, NativeButton and so on) ?
heruan commentedon Nov 30, 2018
What is the benefit of having a button element to navigate, rather than a proper link/anchor? I'd see more benefit to have a link to appear as a button, but just with style. See https://github.com/vaadin/vaadin-lumo-styles/issues/5
pleku commentedon Dec 2, 2018
Some people want a button to look like a link with a theme variant, some people want a link to look like a button with a theme variant... 😃
Currently the
RouterLinkAKA<a router-link>does have some special magic that makes it a special link which blocks the default event handling for the browser. My understanding is that aRouterButtonshould be either aNativeButtonorButton(the Vaadin one) that works 1-1 the same as theRouterLinkin terms of updating the URL and making the server side routing things happen. I would probably even remove the click listener API from it, since it doesn't that much sense when it is used as router link.The
vaadin-buttonweb component will never know anything about the routerlink features in Flow, so I would imagine having just a link that looks like a button is not enough, as you would also want to apply therouter-linkattribute to it if you want to use it for Flow routing. And thus it would be easiest to eithera)
RouterButton extends Composite<Button>(orextends Button) which adds the magicalrouter-linkattributeb)
vaadin-button, and just add that asRouterButton extends RouterLinkpleku commentedon Dec 2, 2018
a) is probably possible without client side changes to Flow, by just having a click listener on server side that triggers the navigation. I'm not sure though everything works the same as with a router link, like postponing navigation, but might be close enough.
knoobie commentedon Dec 5, 2018
Please don't add a 'RouterButton' - just add a theme or a synonym "RouterButton extends RouterLink + add style "button"". See about accessibility concerns: https://marcysutton.com/links-vs-buttons-in-modern-web-applications/
heruan commentedon Jan 23, 2019
I strongly discourage using anything other than anchors (i.e.
<a href>) for navigation: anchors let the browser know what they do and are accessible like @knoobie pointed out.The fact that anchors with the
router-linkattribute have the default behavior prevented to allow in-app navigation is an implementation detail that in my opinion should not justify wrong semantics.I understand there are users coming from past Vaadin versions where navigation was done with buttons and want their app to look alike, but then I'd go with @pleku's (b) solution, i.e. styling the anchor.
satorstefan commentedon Mar 28, 2023
Please don't add a 'RouterButton'
totally-not-ai commentedon Dec 5, 2026
Closing as not planned: a button whose click listener calls
UI.navigate(...)already gives the same result, including navigation lifecycle events such as postponing inBeforeLeaveObserver. For navigation that should behave as a real link (open in new tab, accessibility), useRouterLinkand style it as needed.