Skip to content

Commit 744a0a3

Browse files
javier-godoypaodb
authored andcommitted
fix: fallback to legacy demo
1 parent 196960d commit 744a0a3

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

src/main/java/com/flowingcode/vaadin/addons/demo/RouteTabs.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@ public void add(RouterLink routerLink) {
3636

3737
@Override
3838
public void beforeEnter(BeforeEnterEvent event) {
39-
// In case no tabs will match
4039
setSelectedTab(null);
40+
if (TabbedDemo.class.isAssignableFrom(event.getNavigationTarget())) {
41+
RouterLink first = getFirstRoute();
42+
if (first != null) {
43+
event.forwardTo(first.getHref());
44+
} else {
45+
getChildren().findFirst().ifPresent(tab -> setSelectedTab((Tab) tab));
46+
}
47+
}
4148
}
4249

4350
public Map<RouterLink, Tab> getRouterLinkTabMap() {

src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,14 @@
2929
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
3030
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
3131
import com.vaadin.flow.component.splitlayout.SplitLayout.Orientation;
32-
import com.vaadin.flow.router.BeforeEnterEvent;
33-
import com.vaadin.flow.router.BeforeEnterObserver;
3432
import com.vaadin.flow.router.PageTitle;
3533
import com.vaadin.flow.router.Route;
3634
import com.vaadin.flow.router.RouterLayout;
3735
import com.vaadin.flow.router.RouterLink;
3836

3937
@StyleSheet("context://frontend/styles/commons-demo/shared-styles.css")
4038
@SuppressWarnings("serial")
41-
public class TabbedDemo extends VerticalLayout implements RouterLayout, BeforeEnterObserver {
39+
public class TabbedDemo extends VerticalLayout implements RouterLayout {
4240

4341
private RouteTabs tabs;
4442
private HorizontalLayout footer;
@@ -192,14 +190,4 @@ private void updateSplitterOrientation() {
192190
}
193191
}
194192

195-
@Override
196-
public void beforeEnter(BeforeEnterEvent event) {
197-
if(TabbedDemo.class.isAssignableFrom(event.getNavigationTarget())) {
198-
RouterLink first = tabs.getFirstRoute();
199-
if(first != null) {
200-
event.forwardTo(first.getHref());
201-
}
202-
}
203-
}
204-
205193
}

0 commit comments

Comments
 (0)