Преглед на файлове

#721 fix single page example for multiple clients

Falko Schindler преди 2 години
родител
ревизия
425c20901c
променени са 1 файла, в които са добавени 13 реда и са изтрити 16 реда
  1. 13 16
      examples/single_page_app/main.py

+ 13 - 16
examples/single_page_app/main.py

@@ -3,27 +3,24 @@ from router import Router
 
 from nicegui import ui
 
-router = Router()
 
+@ui.page('/')  # normal index page (eg. the entry point of the app)
+@ui.page('/{_:path}')  # all other pages will be handled by the router but must be registered to also show the SPA index page
+async def main():
+    router = Router()
 
-@router.add('/')
-async def show_one():
-    ui.label('Content One').classes('text-2xl')
-
-
-@router.add('/two')
-async def show_two():
-    ui.label('Content Two').classes('text-2xl')
-
+    @router.add('/')
+    async def show_one():
+        ui.label('Content One').classes('text-2xl')
 
-@router.add('/three')
-async def show_three():
-    ui.label('Content Three').classes('text-2xl')
+    @router.add('/two')
+    async def show_two():
+        ui.label('Content Two').classes('text-2xl')
 
+    @router.add('/three')
+    async def show_three():
+        ui.label('Content Three').classes('text-2xl')
 
-@ui.page('/')  # normal index page (eg. the entry point of the app)
-@ui.page('/{_:path}')  # all other pages will be handled by the router but must be registered to also show the SPA index page
-async def main():
     # adding some navigation buttons to switch between the different pages
     with ui.row():
         ui.button('One', on_click=lambda: router.open(show_one)).classes('w-32')