Skip to main content

Route

Defines a single route in the route tree.

Routes can be nested via children to create layout hierarchies. A route with component and children acts as a layout route — its component should call use_route_outlet to render the matched child.

Parameters:

  • path (str | None, default: None) - Relative path segment. Supports dynamic segments (:name), optional segments (:name?), splats (:name*), and custom regex constraints (:name(\\d+)). None for pathless layout routes.
  • index (bool, default: False) - When True, this route matches when the parent path matches exactly (no further segments). Index routes must not have path or children.
  • component (Callable | None, default: None) - A @component function to render when this route matches.
  • children (list[Route] | None, default: None) - Nested child routes.
  • loader (Callable[..., Any] | None, default: None) - Optional data loader function. Called with the matched params dict when the route matches. Result is available via use_route_loader_data.
  • outlet (bool, default: False) - When True and manage_views=True, this route acts as a layout that wraps its matched child via use_route_outlet within a single View, instead of each child becoming a separate View.
  • modal (bool, default: False) - When True and manage_views=True, the route's View is rendered as a modal overlay on top of the existing stack instead of replacing it. The route's component should set fullscreen_dialog=True on its returned View so Flutter renders the slide-up presentation and a close (X) icon. Placement controls the base stack: * Declared at the top level: a global modal. The base stack is rebuilt from the last non-modal location the Router saw (defaults to "/" on first render). * Declared as a child of a non-modal route: a local modal. The base stack is the chain above the modal in the route tree, so deep-link works from the URL alone. On pop, the Router navigates to the resolved URL of the non-modal parent — never to views[-2].route — so a modal close is always a real navigation back to the base location.
  • recursive (bool, default: False) - When True, the route can match itself as its own descendant — one matched _RouteMatch per consumed segment. Useful for tree-shaped URLs with unbounded depth (e.g. /folder/a/b/c) where each segment should become its own stack entry. Non-recursive children are tried before self-recursion at every depth so a more specific sibling (e.g. example/:gp*) wins over the recursive :slug.

Properties

childrenclass-attributeinstance-attribute

children: list[Route] | None = field(default=None)

componentclass-attributeinstance-attribute

component: Callable | None = None

indexclass-attributeinstance-attribute

index: bool = False

loaderclass-attributeinstance-attribute

loader: Callable[..., Any] | None = None

modalclass-attributeinstance-attribute

modal: bool = False

outletclass-attributeinstance-attribute

outlet: bool = False

pathclass-attributeinstance-attribute

path: str | None = None

recursiveclass-attributeinstance-attribute

recursive: bool = False