Hello, I have completed Talk Python to me training on Anvil. In that training, Michael creates a module for navigation.
This module is used to store all of the navigation code. It is then imported into other forms and modules. The model loads components into homepage form depending on what button is clicked.
However, all of the examples from Anvil the navigation code is stored within the homepage code and uses default slots.
Michael’s example is a fair bit of work. I am wondering what the best practices are for app design in Anvil
The pattern in Talk Python is a great demonstration of how to abstract away similar behaviours into a single module.
My routing abstraction is a little different - I treat the MainForm
as its own abstraction when it comes to navigation.
My MainForm’s one job is to deal with which content Form to load into the .content_panel
(as well as to deal with click events in the navbars)
If I have a subform that needs to call navigation I might do something like
get_open_form().navigate_to('somepage')
since the open_form
is the MainForm
whose only job is to deal with navigation.
Typically I abstract this away further and use HashRouting
which deals with the navigation on behalf of the MainForm
and the equivalent statement would be
from HashRouing import routing
routing.set_url_hash(`somepage`)
here’s a standard design pattern which will give more of a sense of this style of navigation:
2 Likes