create_server_route(cls):
if cls.path is None:
return
@anvil.server.route(cls.path)
def route_handler(*args, **kws):
...
# server an app response
class Route:
def __init_subclass__(cls):
if anvil.is_server_side():
create_server_route(cls)
So far much cleaner than hash routing. I had to fiddle a bit to translate some of the concepts for navigating and caching, passing query parameters etc. but so far so good.
Bonus points for not making me migrate to layouts and allowing for template forms and route forms!! The migration would have been much harder if I had to use layouts too.
From a (admittedly cursory) glance, it seems that the baseline architecture of a Routed app is very different from that of Anvil’s traditional Single-Page app.
That is, I don’t expect to be able to easily or trivially retro-fit anyone’s form of Routing to my large, established, traditional SPA. That would take a new, routing-aware app design. Shared Layouts might help with that…
I haven’t worked with layouts, but I have converted SAP apps into routing apps using Anvil Extras’ old routing module.
The idea was that each form loads everything it needs in its form_show event. Then, instead of using open_form or replacing the form within the main page container for navigation, I switched to routing.set_url_hash(url_pattern='new_page', url_dict=url_dict, load_from_cache=ItDepends).
It wasn’t a smooth process, but it worked. One challenge, for instance, was handling pages with an input box for search and a repeating panel displaying the results. To make it work, the input box’s pressed_enter event had to trigger routing.set_url_hash, and the repeating panel had to be updated using url_dict within the form_show event.