Navigation Best Practices

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