Alternate strategies to share the same styling and behavior across all pages #5062
Replies: 3 comments
-
Actually, I just realized: Could we get That would solve it without requiring wrapping |
Beta Was this translation helpful? Give feedback.
-
Since we released SPA support in 2.22.0, you can use this scheme: @ui.page('/')
@ui.page('/{_:path}') # NOTE: our page should catch all paths
def root():
ui.query('.nicegui-content').classes('w-full')
ui.query('.q-page').classes('flex')
ui.sub_pages({
'/': main,
'/other': other
})
def main():
ui.label('Main page content')
ui.link('Go to other page', '/other')
def other():
ui.label('Another page content')
ui.link('Go to main page', '/') Switching between sub pages is much faster (because only the content is changed without establishing a new connection). And as you can see in the example, you only need to do the setup once. |
Beta Was this translation helpful? Give feedback.
-
Another alternative - if you just want to apply some classes via ui.add_head_html('''
<style type="text/tailwindcss">
.nicegui-content {
@apply bg-blue-100;
}
</style>
''', shared=True) See https://nicegui.io/documentation/section_styling_appearance#tailwind_css_layers for another demo about using CSS' |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Disclaimer: I already saw the example here.
But in my case I don't need a
context_manager
/yield
because I just want to do someui.query
at the top of eachpage
:nicegui/examples/chat_with_ai/main.py
Lines 34 to 36 in b058c3b
Trivial solution is:
But awkward to have to remember to
setup()
eachpage
. Wrapping thepage
decorator would be great.This works:
But two outstanding issues:
Not sure how would handleasync
pages.iscoroutinefunction
to the rescue.Comments / ideas welcome! 🙏🏻
Beta Was this translation helpful? Give feedback.
All reactions