Skip to content

Commit c8ff229

Browse files
authored
fix: Clean outlet automatically (#19851)
Remove outlet for layout element automatically so that we don't end up with multiple outlets on the page.
1 parent 3dc38a6 commit c8ff229

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

flow-server/src/main/java/com/vaadin/flow/component/internal/UIInternals.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import com.vaadin.flow.component.HasElement;
4242
import com.vaadin.flow.component.HeartbeatEvent;
4343
import com.vaadin.flow.component.HeartbeatListener;
44+
import com.vaadin.flow.component.Tag;
4445
import com.vaadin.flow.component.UI;
4546
import com.vaadin.flow.component.dependency.JavaScript;
4647
import com.vaadin.flow.component.dependency.StyleSheet;
@@ -855,7 +856,13 @@ && getRouter().getRegistry()
855856
.createComponent((Class<? extends Component>) getClass()
856857
.getClassLoader().loadClass(
857858
"com.vaadin.flow.component.react.ReactRouterOutlet"));
858-
((RouterLayout) target).showRouterLayoutContent(reactOutlet);
859+
RouterLayout layout = (RouterLayout) target;
860+
layout.getElement().getChildren()
861+
.filter(element -> element.getTag()
862+
.equals(reactOutlet.getClass()
863+
.getAnnotation(Tag.class).value()))
864+
.forEach(Element::removeFromParent);
865+
layout.showRouterLayoutContent(reactOutlet);
859866
} catch (ClassNotFoundException e) {
860867
throw new IllegalStateException(
861868
"No ReactRouterOutlet available on classpath", e);

0 commit comments

Comments
 (0)