Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
11.62k
stars
455
forks
source link
After refreshing the web page, the route refreshes to the first tab, but the page content still stays on the original page #4006
Closed
huqunfeng closed 4 weeks ago
Duplicate Check
Describe the bug
After refreshing the web page, the route refreshes to the first tab, but the page content still stays on the original page
Code sample
Code
```python [import flet as ft from globalvar import env import UserLogin from orderfile import orderpage from pilefile import pilepage from settlefile import settlepage from userfile import userpage from esfile import espage from redisfile import redispage import requests from globalvar import ipaddress def main(page: ft.Page): global token page.title = f"万马爱充查询工具({env})" page.fonts = { "globalfont": "fonts/msyh.ttc", } page.theme = ft.Theme(font_family="globalfont") page.appbar = ft.AppBar( leading=ft.Row(controls=[ft.Container(width=5), ft.Image(src='./icons/wanmalogo2.png', width=40, height=12.4)]), toolbar_height=30, title=ft.Text(f"万马爱充自助查询工具({env})", size=13), center_title=True, bgcolor= '#F7AB00', #bgcolor=ft.colors.ORANGE ) page1 = orderpage.OrderPage() page2 = pilepage.PilePage() page3 = userpage.UserPage() page4 = settlepage.SettlePage() page5 = espage.EsPage() page6 = redispage.RedisPage() pagelist = [page1, page2, page3, page4, page5, page6] if page.client_storage.contains_key("token"): token = page.client_storage.get("token") headers = \ { "Content-Type": "application/json;charset=UTF-8" } checktokenurl = f"http://{ipaddress}/check_token?token={token}" result = requests.post(checktokenurl, headers=headers) if result.status_code == 401: page.route = '/' else: page.route = "/root" else: page.route = '/' def route_change(route): page.views.clear() if page.route == "/root": def PageUpdate(num): datepage.controls = [pagelist[num]] page.update() datepage = ft.View( route="/root", appbar=page.appbar, scroll=ft.ScrollMode.ADAPTIVE, adaptive=True, controls=[page1], navigation_bar=ft.NavigationBar( bgcolor='#F7AB00', #bgcolor=ft.colors.ORANGE, indicator_color=ft.colors.WHITE, on_change=lambda e: PageUpdate(e.control.selected_index), destinations=[ ft.NavigationBarDestination(icon=ft.icons.QUERY_STATS, label="订单查询"), ft.NavigationBarDestination(icon=ft.icons.EV_STATION, label="电桩查询"), ft.NavigationBarDestination(icon=ft.icons.PEOPLE, label="用户查询"), ft.NavigationBarDestination(icon=ft.icons.PAYMENT, label="人工结算"), ft.NavigationBarDestination(icon=ft.icons.DATA_OBJECT, label="ES查询"), ft.NavigationBarDestination(icon=ft.icons.DATA_USAGE, label="Redis查询") ], selected_index=0, ) ) page.views.append( datepage ) if page.route == "/": page.views.append( ft.View( "/", [ UserLogin.Login() ], appbar=page.appbar, auto_scroll=True ) ) page.update() def view_pop(view): page.views.pop() top_view = page.views[-1] page.go(top_view.route) page.on_route_change = route_change page.on_view_pop = view_pop page.go(page.route) ft.app(target=main) ] ```To reproduce
After refreshing the web page, the route refreshes to the first tab, but the page content still stays on the original page
Expected behavior
No response
Screenshots / Videos
Captures
[Upload media here]Operating System
Windows
Operating system details
windows 11
Flet version
0.23.2
Regression
No, it isn't
Suggestions
No response
Logs
Logs
```console [Paste your logs here] ```Additional details
No response