flow icon indicating copy to clipboard operation
flow copied to clipboard

Router: Let @RouteAlias read the layout from the @Route annotation by default

Open haiwan opened this issue 6 years ago • 2 comments

It happens quite often that when defining a @RouteAlias, people forget to set the value for layout. Also, since the layout is already defined in the @Route, so probably it makes more sense to just use that value by default, rather than having to repeat it for @RouteAlias

haiwan avatar Jun 26 '19 10:06 haiwan

This requires further thinking and a proper design. RouteAlias allows to specify any RouteLayout as well as don't specify any layout. In the last case it means that the component should be used as is. And this is totally fine.

You suggestion makes impossible to use a component without any layout at all. So it disables one usecase without any way to enable it back.

We either should remove layout parameter at all in this case or find some other solution.

denis-anisimov avatar Jul 10 '19 11:07 denis-anisimov

Bump.

@Route(value = "", layout = MainLayout.class)
@RouteAlias("login")
public class MainView extends VerticalLayout {}

I'd intuitively expect @RouteAlias to inherit layout from @Route. However, the actual behavior depends on where you navigate: when navigating to "" you'll get MainView wrapped in MainLayout, navigating to "login" yields MainView without MainLayout.

This can be spotted easily, true, unless you're using @RouteScope @RouteScopeOwner(MainLayout.class), then you'll get a nasty Spring stacktrace instead:

Caused by: java.lang.IllegalStateException: Route owner 'class org.vaadin.example.MainLayout' instance is not available in the active navigation components chain: the scope defined by the bean 'mainView' doesn't exist.
	at com.vaadin.flow.spring.scopes.VaadinRouteScope$RouteBeanStore.doGet(VaadinRouteScope.java:328)
	at com.vaadin.flow.spring.scopes.BeanStore.lambda$get$0(BeanStore.java:64)

I scratched my head for 2 hours on this until it hit me that @RouteAlias doesn't inherit layout from @Route!!!

mvysny avatar Oct 01 '24 12:10 mvysny