router.sub_pages Not Supported – Difficult to Implement Nested Page Layouts #5083
Replies: 3 comments 1 reply
-
I tried using ui.sub_pages({
'/': home_page,
'/settings': settings_page
}, root_path='/dashboard').classes('h-full') While this works, it requires manually setting |
Beta Was this translation helpful? Give feedback.
-
For me it works when applying the modularization example: from nicegui import APIRouter, app, ui
router = APIRouter(prefix='/dashboard', tags=['dashboard'])
def home_page():
with ui.card().tight().classes('m-6 p-6 shadow-lg'):
ui.label('Home Page').classes('text-3xl font-bold mb-2 text-gray-800')
ui.label('Welcome to the admin system!').classes('text-gray-700 mb-4')
ui.button('Go to Settings', on_click=lambda: ui.navigate.to('/dashboard/settings'))
def settings_page():
with ui.card().tight().classes('m-6 p-6 shadow-lg'):
ui.label('Settings').classes('text-3xl font-bold mb-2 text-gray-800')
ui.label('Configure your system here.').classes('text-gray-700 mb-4')
ui.button('Back to Home', on_click=lambda: ui.navigate.to('/dashboard'))
@router.page('/')
@router.page('/{_:path}')
def index():
ui.label('Hello World')
ui.sub_pages({
'/dashboard': home_page,
'/dashboard/settings': settings_page
}).classes('h-full')
app.include_router(router)
ui.run() |
Beta Was this translation helpful? Give feedback.
-
Ah sorry, I missed the optimization by using ui.sub_pages({
'/': home_page,
'/settings': settings_page
}, root_path=router.prefix) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, NiceGUI does not support
router.sub_pages
, which makes it inconvenient to implement nested page layouts or multi-page dashboards with consistent sidebar and top navigation.For example, in a typical admin system setup:
In this layout:
top_navbar()
andsidebar_menu()
are shared across pages.ui.sub_pages
is used to dynamically render nested content.Problems:
router.sub_pages
.Request / Feature Suggestion:
router.sub_pages
or a similar mechanism to allow nested pages with shared layouts.Example Expected Behavior:
Navigating to
/dashboard/settings
should render thesettings_page
inside the main content area without duplicating the sidebar and navbar code.This feature would greatly simplify building admin dashboards and multi-page applications in NiceGUI.
Beta Was this translation helpful? Give feedback.
All reactions