navigate_documentation.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.navigate)
  4. def main_demo() -> None:
  5. with ui.row():
  6. ui.button('Back', on_click=ui.navigate.back)
  7. ui.button('Forward', on_click=ui.navigate.forward)
  8. ui.button('Reload', on_click=ui.navigate.reload)
  9. ui.button(icon='savings',
  10. on_click=lambda: ui.navigate.to('https://github.com/sponsors/zauberzeug'))
  11. @doc.demo(ui.navigate.to)
  12. def open_github() -> None:
  13. url = 'https://github.com/zauberzeug/nicegui/'
  14. ui.button('Open GitHub', on_click=lambda: ui.navigate.to(url, new_tab=True))
  15. @doc.demo('Push and replace URLs', '''
  16. The `history` API allows you to push and replace URLs to the browser history.
  17. While the `history.push` method pushes a new URL to the history,
  18. the `history.replace` method replaces the current URL.
  19. See `JavaScript's History API <https://developer.mozilla.org/en-US/docs/Web/API/History>`_ for more information.
  20. *Added in version 2.13.0*
  21. ''')
  22. def history_demo() -> None:
  23. ui.button('Push URL', on_click=lambda: ui.navigate.history.push('/a'))
  24. ui.button('Replace URL', on_click=lambda: ui.navigate.history.replace('/b'))