Skip to content

React Router Full Page Load while clicking link in dialog #19630

Closed

Description

@knoobie

Description of the bug

When I click a RouterLink within a Dialog I expect that the already rendered MainLayout is shown / preserved and no white background / full page reload happens.

Expected behavior

No full page load.

Minimal reproducible example

https://drive.google.com/file/d/1Pb2Rm-7CZPKU0HwGtYdvbNJheXPa0l2W/view?usp=sharing

I’ve added coloring and thread.sleep to make the problem more obvious.

Clicking the link in the MainView: ok
Clicking the link in the Dialog of the MainView: not okay

Versions

  • Vaadin / Flow version: 24.4.3

Activity

  1. AlainaFaisal commented on Jun 25, 2024

    @AlainaFaisal
    Contributor

    This problem might be occurring because when a RouterLink is used inside a dialog, it tries to navigate as if it's part of the main layout, which is not fully compatible with how dialogs handle their content. Dialogs are generally meant for small, self-contained interactions and are not designed to handle navigation or the lifecycle of routing in the same way as components directly managed by the router.
    You can try to change the RouterLink to a Button and manually handle the navigation. This can prevent the default routing behavior that causes the full page reload.

    For example this way:
    ` Button button = new Button("Click me to open dialog with link", event -> {

      Dialog dialog = new Dialog();
      dialog.add(new Button("Navigate to Other View", e -> {
        UI.getCurrent().navigate(OtherView.class);
        dialog.close(); // Close the dialog upon navigation
      }));
    
      dialog.setHeaderTitle("Moin");
      dialog.open();
    
    });`
    
  2. knoobie commented on Jun 25, 2024

    @knoobie
    ContributorAuthor

    You are new, so you don't know the full picture here. RouterLink have to work in dialog: see #13270

  3. added a commit that references this issue on Jun 25, 2024
    9885abd
  4. self-assigned this
    on Jun 25, 2024
  5. added
    BFPBugfix priority, also known as Warranty
    on Jun 26, 2024
  6. moved this to 🔖 High Priority (P1) in Vaadin Flow bugs & maintenanceon Jun 26, 2024
  7. moved this from 🟢Ready to Go to 🔎Iteration reviews in Vaadin Flow | Hilla | Kits ongoing workon Jun 26, 2024
  8. moved this from 🔖 High Priority (P1) to ✅ Closed in Vaadin Flow bugs & maintenanceon Jun 27, 2024
  9. added 2 commits that reference this issue on Jun 27, 2024
    09cae2b
    e209d14
  10. added a commit that references this issue on Jul 2, 2024
    04a116f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions