Project Structure #278
-
|
Hi there! - pages
- home.py
- config.py
main.pyIn the main file, I just want to call my pages or elements that construct my pages: import flet
from flet import Page, Text
from pages.home import Home
from pages.config import Config
def main(page: Page):
page.add(Text(f"Initial route: {page.route}"))
def route_change(route):
page.views.clear()
if page.route == '/Config':
page.views.append(Config())
else:
page.views.append(Home())
page.update()
page.on_route_change = route_change
flet.app(target=main)And then, in the Home.py, I would like to have something like this (same idea for the Config.py file): from flet import UserControl, Text, ElevatedButton, Column
class Home(UserControl):
def go_to_config(self, e):
page.route = '/Config'
def build(self):
return Column(controls=[
Text('Home page'),
ElevatedButton('Go to Config page', on_click=go_to_config)
])For the moment the idea does not work, but I was wondering if I'm misunderstanding how flet should work, or if they are better ways to do that. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
The problem is in |
Beta Was this translation helpful? Give feedback.
-
|
https://github.com/flet-dev/examples/blob/main/python/apps/routing-navigation/home-store.py#L25 |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @FeodorFitsner! |
Beta Was this translation helpful? Give feedback.
The problem is in
go_to_config(). After changingpage.routeproperty you have to callpage.update().But I'd rather use
page.go('/Config')which additionally calls route change handler without roundtrip to a client.