HashRouting: Routing, navigation with URL Hash

Updates:

I’ve included the following features

routing.go_back()
routing.go(0) # equivalent to refresh
routing.go(-1) # equivalent to routing.go_back
routing.reload_page() # just replace the content panel (but not from cache)
routing.reload_page(hard=True) # reload the page # equivalent to routing.go(0)

for the issue regarding SessionExpiredError
@jshaffstall was using a solution I suggestion here:

Apparently that solution is wrong! You can’t catch SessionExpiredErrors with a custom error handler. :man_facepalming:

Anvil’s behaviour is to reload the page with the href (thereby losing the url_hash)

So i’ve added a feature

routing.on_session_expired(reload_hash=True, allow_cancel=True)
# default behaviour as per anvil is reload_hash=False, allow_cancel=True

The session expired alert will happen as before but it will change the behaviour of the refresh now button

best place to call this is probably above your @routing.main_router form

To test this feature you can create a button that does

def button_click(self, **event_args):
  raise anvil.server.SessionExpiredError()
4 Likes