Skip to main content

Routing / Toolbar

This example demonstrates how you can observe and handle changes to the browser's location hash.

The location hash can be accessed using q.args['#'].

from h2o_wave import main, app, Q, ui

async def serve(q: Q):
if not q.client.initialized:['nav'] = ui.toolbar_card(
box='1 1 4 1',
ui.command(name='#menu/spam', label='Spam'),
ui.command(name='#menu/ham', label='Ham'),
ui.command(name='#menu/eggs', label='Eggs'),
ui.command(name='#about', label='About'),
)['blurb'] = ui.markdown_card(
box='1 2 4 2',
content='Welcome to our store!',
q.client.initialized = True
hash = q.args['#']
if hash:
blurb =['blurb']
if hash == 'menu/spam':
blurb.content = "Sorry, we're out of spam!"
elif hash == 'menu/ham':
blurb.content = "Sorry, we're out of ham!"
elif hash == 'menu/eggs':
blurb.content = "Sorry, we're out of eggs!"
elif hash == 'about':
blurb.content = 'Everything here is gluten-free!'

Tags:  routingtoolbar