Context: Vaadin 21, Java 8.
On top of a Vaadin 21 sample application (from https://start.vaadin.com/app/ ) I wrote my own RouterLayout
with navigation bar on top, body in the middle and footer at the bottom (as exchange for the MainLayout
in the sample application).
In the navigation bar I put a MenuBar
( https://vaadin.com/docs/latest/ds/components/menu-bar ) with some RouterLink
s in it.
When the user clicks at one of the RouterLink
s in the MenuBar
, then the whole page refreshes and also my RouterLayout
is reinstantiated (= constructor is called).
When I exchange the MenuBar
by a Tabs
component ( https://vaadin.com/docs/latest/ds/components/tabs ), then the click at the same RouterLink
as before just exchanges the content of the body in the RouterLayout
(as expected).
I know this hint at https://vaadin.com/docs/latest/ds/components/menu-bar, but I don't know why there is a difference between MenuBar
and Tabs
:
Menu Bar should not be used for navigation. Use tabs for switching between content, or anchor elements for regular navigation.
So my questions are:
- Why is there a difference (the page refresh) between
MenuBar
andTabs
in navigation, even when I use the same code forRouterLink
creation in both cases? - Why should the
MenuBar
not be used for navigation? - Is there a way to do navigation without page refresh with the
MenuBar
?