Is it possible to change/update routing table of t...
# ballast
r
Is it possible to change/update routing table of the routing view model? The routing table seems to be implemented as state, so it should be possible, am I right?
c
The main way to do that now is to either create a new Router with the updated routes, or else create a custom implementation of
RoutingTable
that handles the more dynamic matching logic. Here’s the implementation for enums to show that it’s a pretty trivial to make a custom RoutingTable, and matching is always done dynamically at the time that navigation is requested, so you can provide any kind of dynamic logic you need within your custom RoutingTable class. Just changing the RoutingTable within a Router isn’t supported right now though, mostly because I haven’t thought through the semantic meaning of that yet. How should changing the RoutingTable impact the Backstack, for example? And I couldn’t think of any scenarios where one would need to replace the RoutingTable at runtime, but I would definitely like to know if you’ve got a scenario in mind.
r
Some KVision components (e.g. TabPanel) can dynamically register routes at runtime (e.g. I can add new tab with a route at any time). I already have a router abstraction in KVision, which is implemented by different routing modules. I would like ballast module to implement the same abstraction. I will try with custom routing table. Thank you.
c
If that doesn’t work or looks a bit too hacky, you also could basically provide your own Router implementation which is able to update the RoutingTable. It basically just needs a custom
InputHandler
(here’s the original you can copy as the base) and an Input that will update the property. As you noted in the original question, it is ultimately just a property of the Router ViewModel’s State, and can be swapped out from within the custom InputHandler