Skip to content

Add declarative Router with view-stack navigation#6406

Open
FeodorFitsner wants to merge 14 commits intorelease/v0.85.0from
router-3
Open

Add declarative Router with view-stack navigation#6406
FeodorFitsner wants to merge 14 commits intorelease/v0.85.0from
router-3

Conversation

@FeodorFitsner
Copy link
Copy Markdown
Contributor

@FeodorFitsner FeodorFitsner commented Apr 10, 2026

Summary

  • Add ft.Router declarative routing component for @ft.component apps with nested routes, layout routes (outlets), dynamic segments, optional segments, splats, custom regex, and data loaders
  • Add hooks: use_route_params, use_route_location, use_route_outlet, use_route_loader_data, is_route_active
  • Add manage_views=True mode for view-stack navigation — enables swipe-back gestures, system back button, and AppBar implicit back button on mobile
  • Add outlet=True flag on Route for shared layouts wrapping child views
  • Add Page.navigate() sync wrapper for Page.push_route() from synchronous callbacks
  • Add visible attribute to Component so functional components can be used as content of controls like SafeArea that require visible content
  • Convert all router docs to docusaurus/crocodocs format with reST cross-references in docstrings
  • Add 14 router example apps including `nested_routes`, `nested_outlet_views`, and `featured_views` (full app with NavigationRail)

Test plan

  • Run `sdk/python/examples/apps/router/basic` — basic flat routing
  • Run `sdk/python/examples/apps/router/nested_routes` — verify back button and swipe-back work between nested route levels
  • Run `sdk/python/examples/apps/router/nested_outlet_views` — verify shared layout wraps each child view
  • Run `sdk/python/examples/apps/router/featured_views` — verify NavigationRail with mixed stacked + tabbed navigation, no transition animation between top-level pages
  • Verify all existing router examples (`active_links`, `auth_dialog`, `auth_page`, `dynamic_segments`, `featured`, `index_routes`, `layout_outlet`, `loaders`, `prefix_routes`, `runtime_routes`, `splats`) still work
  • Verify docs build: `cd website && yarn build`

Summary by Sourcery

Introduce a declarative Router system for component-based Flet apps, including view-stack navigation support, new routing hooks, and updated docs and examples.

New Features:

  • Add Router, Route, LocationInfo, and related hooks for declarative, component-based routing with nested routes, loaders, and active-link detection.
  • Add manage_views support to Router for building stacked View-based navigation with back gestures and AppBar back buttons.
  • Expose a synchronous Page.navigate() helper for routing from non-async callbacks.
  • Allow components to control visibility via a new visible attribute for use inside container-like controls.

Enhancements:

  • Relax Page.render and render_views component type hints to accept any callable, improving flexibility for routed component trees.

Documentation:

  • Document the new Router control, routing hooks, and related types, and add a dedicated Router cookbook section.
  • Register Router and new routing types in the Docusaurus sidebar navigation.
  • Add README and metadata for new router example applications.

Tests:

  • Add a suite of router example apps demonstrating basic routing, nested and prefix routes, loaders, auth guards, dynamic segments, splats, and managed view stacks.

Introduce Page.navigate(route, **kwargs) as a synchronous convenience wrapper that schedules an async push_route via asyncio.create_task. Useful for synchronous callbacks (e.g. on_click) where awaiting is not possible; forwards route and query parameters to push_route.
Replace the inline Stack/Card login overlay with a modal AlertDialog using page.show_dialog/pop_dialog in AuthGuard. Add page context, a show_login helper, and a use_effect to open/close the dialog based on auth state. In auth_page, show a ProgressRing when auth is not yet available in Dashboard, and move navigation to /login into a use_effect in ProtectedRoute (also guard against auth being None) to avoid performing navigation as a render side effect.
Export ContextProvider from use_context and add type annotations across router, page, and example files to improve typing/IDE support. Examples (auth_dialog, auth_page, featured) now declare AuthContext with ft.ContextProvider[AuthState | None]. Router typings updated (use_route_outlet and Router now return Control) and TYPE_CHECKING is used to avoid runtime imports. Page.render and Page.render_views signatures were simplified to accept Callable[..., Any].
Move router example scripts into per-example subfolders (main.py) and add corresponding pyproject.toml metadata for gallery packaging. Wrap example App components with SafeArea and replace unconditional ft.run calls with an if __name__ == "__main__" guard. Remove the old top-level example files and update docs (controls and cookbook) to reference the new example paths and updated navigation API usage.
Router with manage_views=True returns a list of Views (one per path
level) enabling swipe-back gestures, system back button, and AppBar
implicit back button on mobile. Used with page.render_views().

- Add manage_views parameter to Router
- Add outlet flag to Route for shared layouts across child views
- Add _split_chain_into_view_levels and _build_view_level helpers
- Handle on_view_pop for back navigation
- Allow pathless routes with children to match as standalone views
- Update nested_routes example to use manage_views
- Add nested_outlet_views example with shared layout
- Add featured_views example with NavigationRail, Projects (stacked
  views with back navigation), and Settings (tabbed outlet layout)
- Move example descriptions from module docstrings to README.md files
  for nested_routes, nested_outlet_views, and featured_views
- Convert Python docstrings to reST cross-reference roles
- Convert controls/router.md to JSX with ClassSummary, ClassMembers,
  CodeExample components; add managed views examples
- Convert 7 type docs from jinja stubs to JSX with ClassAll
- Rewrite cookbook/router.md with short inline snippets, links to full
  examples, and new sections for manage_views, outlet=True, and
  NavigationRail patterns
- Update navigation-and-routing.md to mention manage_views mode
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 10, 2026

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 210206e
Status: ✅  Deploy successful!
Preview URL: https://3eb40707.flet-website-v2.pages.dev
Branch Preview URL: https://router-3.flet-website-v2.pages.dev

View logs

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 10, 2026

Deploying flet-examples with  Cloudflare Pages  Cloudflare Pages

Latest commit: 210206e
Status: ✅  Deploy successful!
Preview URL: https://caca4d45.flet-examples.pages.dev
Branch Preview URL: https://router-3.flet-examples.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant