Skip to content

Commit

Permalink
fix: Clean outlet automatically (#19851)
Browse files Browse the repository at this point in the history
Remove outlet for layout element
automatically so that we don't
end up with multiple outlets
on the page.
  • Loading branch information
caalador authored Aug 30, 2024
1 parent 3dc38a6 commit c8ff229
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.vaadin.flow.component.HasElement;
import com.vaadin.flow.component.HeartbeatEvent;
import com.vaadin.flow.component.HeartbeatListener;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.dependency.JavaScript;
import com.vaadin.flow.component.dependency.StyleSheet;
Expand Down Expand Up @@ -855,7 +856,13 @@ && getRouter().getRegistry()
.createComponent((Class<? extends Component>) getClass()
.getClassLoader().loadClass(
"com.vaadin.flow.component.react.ReactRouterOutlet"));
((RouterLayout) target).showRouterLayoutContent(reactOutlet);
RouterLayout layout = (RouterLayout) target;
layout.getElement().getChildren()
.filter(element -> element.getTag()
.equals(reactOutlet.getClass()
.getAnnotation(Tag.class).value()))
.forEach(Element::removeFromParent);
layout.showRouterLayoutContent(reactOutlet);
} catch (ClassNotFoundException e) {
throw new IllegalStateException(
"No ReactRouterOutlet available on classpath", e);
Expand Down

0 comments on commit c8ff229

Please sign in to comment.