@Route(..., layout=MyLayout.class) dynamically / programmatically / a littl

The problem

What I am missing in Vaadin 10/11 is a way to specify the layout of a @Route without having to explicitly reference the layout class.
I’d rather would like to reference a layout “name” or “ID” for loose coupling.
Currently there is very tight coupling between my @Route class and the layout it is used in.
In my opinion the Route component should not be forced to know about the surrounding layout at compile time.

Something like this would be nice:

Annotate the RouterLayout and give it an unique ID

@RouteLayout(value="mainUi")
class MainUi extends Div implements RouterLayout {
 ...
}

@Route(value="", layoutId="mainUi")
class MyRoute extends Div{
}

It would be even nicer, if i could hook into resolving the layoutId mechanism.

Is there some workaround to achieve something similar?

Also related to this topic:
https://vaadin.com/forum/thread/17225666/registering-routes-dynamically
https://github.com/vaadin/flow/issues/3913

Some backround information
Why we need this:
I am working on an application project that tries to keep everything in modules. The application is just a dumb empty frame with basic functionality like main layout, login, menu, notifications, messaging etc. This basic application is then complemented by modules that provide actual views and functionality. “Everything is a module”

The structure of the projects is roughly like this

  • UI API project: used by modules to access UI services like menu and other things. Contains mostly interfaces and has no dependencies to Vaadin. It is UI technology neutral
  • Vaadin 11 application project: The actual “dumb” application. Implements the UI API using Vaadin 11. Also contains the main RouterLayout “MainUi”.
  • Module 1…X: The module projects that complement the application. Only uses UI API to “hook” into main application. No dependency to the actual Vaadin 11 application project. SO it could be used for other application projects that provide the same API

Modules do not include the Vaadin 11 application project as a dependency. The only use the UI API project. So theoretically they could be used in another (vaadin) application that provides the same UI API.

The problem now is:
If a module adds a @Route that should be displayed within in the MainUi it needs to do this:
@Route(value = “myView”, layout=MainUi.class)
It needs to reference the MainUi class from our application project and we don’t want that dependency. We consider that class an implementation detail that now leaks to the outside. It would be better for us to reference an ID that is resolved at runtime.