Skip to content

RouterButton #2231

Not planned
Not planned

Description

@Legioth

Like RouterLink, but instead a button with a client-side click listener that navigates to the URL of the configured view.

Activity

  1. gilberto-torrezan commented on Aug 24, 2017

    @gilberto-torrezan
    Contributor

    Would it be possible to have a generic API that could be used for any kind of button (VaadinButton, PaperButton, NativeButton and so on) ?

  2. heruan commented on Nov 30, 2018

    @heruan
    Member

    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

  3. pleku commented on Dec 2, 2018

    @pleku

    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)

    1. Make RouterButton extends Composite<Button> (or extends Button) which adds the magical router-link attribute
    2. Make Flow client side handle the click events from those buttons like the router links.

    b)

    1. Make it somehow possible to have an anchor that is themeable as the vaadin-button, and just add that as RouterButton extends RouterLink
  4. pleku commented on Dec 2, 2018

    @pleku

    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.

  5. knoobie commented on Dec 5, 2018

    @knoobie
    Contributor

    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/

  6. heruan commented on Jan 23, 2019

    @heruan
    Member

    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.

  7. satorstefan commented on Mar 28, 2023

    @satorstefan

    Please don't add a 'RouterButton'

  8. totally-not-ai commented on Dec 5, 2026

    @totally-not-ai
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions