Skip to content

SLG Router

alx-net edited this page Jun 27, 2024 · 4 revisions

SLGRouter is the class which handles navigation within our app. The instance of this class manages all the pages in the app by putting them into an dictionary with a string as key and page as value. Everything this Router does is showing and hiding pages.

Route String Page Instance
/home SLGHomePageView instance
/home/Data Types SLGTopicPageView instance with "Data Types" data
... ...
  • We show only one page at the time
  • The Route string can be an arbitrary string of any format

Route to a specific page:

navigateTo: '/home'

Navigate back

There is also a method called navigateBack which returns to the previous page. This is implemented as a stack. Each time we navigate, we add a page to the stack. This means the page which is visible is always on top of the stack. This means navigating back means popping the stack.

Updating a page on navigateTo

When we navigate to a page we potentially want it to update some of it's UI components. The router tries to call a method named refresh in case the page has this method implemented. A refresh method is optionally.

All pages have access to the navigateTo: ... and navigateBack method. The router is passed as part of SLGMainController to all the pages.

Example Code

| router |
router := SLGRouter new.

" Register routes "
router addRouteWithPath: '/home' withPage: Morph new.
router addRouteWithPath: '/home/subpage1' withPage: Morph new.

" Shows homepage "
router navigateTo: '/home'. 

" Hides homepage and  shows subpage "
router navigateTo: '/home/subpage1'.

" Hides subpage and shows homepage "
router navigateBack.
Clone this wiki locally