When deploying an app, I want to configure the routes for it dynamically, because the routes depend on a deployment configuration and I don't want to change the app code for this
When building an app, I want to dynamically remove routes, because business data has changed and those views should not be available anymore for the users (eg. subscription expired)
flow-demos for this particular featureAdding routes dynamically that shows how what to doHow thread safe does it have to be? Is it enough that each individual addition or removal is atomic, or would it be necessary to also support "transactions" where multiple modifications are done in one go without any possibility for another thread to detect a situation where some changes are in effect but not all of them?
The "legacy router" forced a transactional approach because of the way you first had to register the route, and then separately (or through a shorthand) define which parent layout to use for the recently registered route. Without transactional registering, there would have been a short time when a user could have navigated to a route that didn't have the right parent.
If we instead structure the API so that everything needed for one route is registered at once (including any shorthands), then the need for transactional registering is significantly reduced (as long as we still prevent corruption and ensure typical happens-before relationships).
That's a good question and note.
In the end it depends on the resulting API.
May be we should fist ignore thread safety (keeping it in mind). And make API without transactional support.
Then refactor it a bit (using callbacks most likely though API will be moved to another classes perhaps).
We are going to at some point most likely maybe perhaps add a way to register dynamically routes that don't have a Java class, but eg. just a HTML file.
I started writing out my thoughts for how to deal with this in https://github.com/vaadin/flow/issues/3467#issuecomment-441724774. Contrary to what I had assumed before writing it out, it seems like there would not be any direct relationship between the two cases. The only directly needed addition would be something like HasDynamicParent, but that will most likely not have any direct impact on dynamic registration either.
The ticket https://github.com/vaadin/flow/issues/4820 may be a part of this one.
I'm not sure how we are going to implement application scope route registry: whether we store all the static routes info inside this registry or separately.
Most helpful comment
How thread safe does it have to be? Is it enough that each individual addition or removal is atomic, or would it be necessary to also support "transactions" where multiple modifications are done in one go without any possibility for another thread to detect a situation where some changes are in effect but not all of them?
The "legacy router" forced a transactional approach because of the way you first had to register the route, and then separately (or through a shorthand) define which parent layout to use for the recently registered route. Without transactional registering, there would have been a short time when a user could have navigated to a route that didn't have the right parent.
If we instead structure the API so that everything needed for one route is registered at once (including any shorthands), then the need for transactional registering is significantly reduced (as long as we still prevent corruption and ensure typical happens-before relationships).