api_router_example.py 850 B

123456789101112131415161718192021222324
  1. import theme
  2. from message import message
  3. from nicegui import APIRouter, ui
  4. # NOTE: the APIRouter does not yet work with NiceGUI On Air (see https://github.com/zauberzeug/nicegui/discussions/2792)
  5. router = APIRouter(prefix='/c')
  6. @router.page('/')
  7. def example_page():
  8. with theme.frame('- Page C -'):
  9. message('Page C')
  10. ui.label('This page and its subpages are created using an APIRouter.')
  11. ui.link('Item 1', '/c/items/1').classes('text-xl text-grey-8')
  12. ui.link('Item 2', '/c/items/2').classes('text-xl text-grey-8')
  13. ui.link('Item 3', '/c/items/3').classes('text-xl text-grey-8')
  14. @router.page('/items/{item_id}', dark=True)
  15. def item(item_id: str):
  16. with theme.frame(f'- Page C{item_id} -'):
  17. message(f'Item #{item_id}')
  18. ui.link('go back', router.prefix).classes('text-xl text-grey-8')