BloomRoute class

Route definition that pairs a URL path pattern with view builders, loaders, and guards.

Represents a single route or route subtree in a BloomRouter.

Path Pattern Syntax

  • Static segments: /users/list matches /users/list exactly.
  • Dynamic parameters: /users/:id matches /users/42 and extracts {'id': '42'} into the params map. Parameter values are automatically URI-decoded.
  • Wildcards: /docs/* matches /docs/guide/start and extracts the remaining path under the 'wildcard' key ({'wildcard': 'guide/start'}).
  • Root route: '' or '/' matches the root path.

Data Loaders and Suspense

When loader is provided, entering this route automatically wraps the route content in a Suspense boundary. While loader is executing, loadingFallback (or an empty fragment if omitted) is rendered. Once resolved, dataBuilder is called with both the route params and the loaded data. If dataBuilder is omitted, builder is called with params alone.

final userRoute = BloomRoute(
  '/users/:id',
  null,
  loader: (params) => fetchUserProfile(params['id']!),
  loadingFallback: () => const Div(text: 'Loading user...'),
  dataBuilder: (params, user) => Div(
    children: [
      H1(text: 'User: ${(user as User).name}'),
    ],
  ),
);

Persistent Shell Routes

Use BloomRoute.shell to wrap nested sub-routes in persistent layout chrome (such as navigation sidebars and headers) without affecting URL hierarchy.

Constructors

BloomRoute(String path, BloomNode builder(Map<String, String> params)?, {BloomNode layout(BloomNode child, Map<String, String> params)?, List<BloomRouteGuard> guards = const [], List<BloomRoute> children = const [], Future loader(Map<String, String> params)?, BloomNode dataBuilder(Map<String, String> params, dynamic data)?, BloomNode loadingFallback()?})
Creates a route definition matching path.
const
BloomRoute.shell({required BloomNode layout(BloomNode child, Map<String, String> params), required List<BloomRoute> routes, List<BloomRouteGuard> guards = const []})
Factory constructor for persistent shell layouts enclosing nested routes.
factory

Properties

builder BloomNode Function(Map<String, String> params)?
Builder that receives extracted params and returns a BloomNode tree.
final
children List<BloomRoute>
Nested child routes matched within this route's hierarchy.
final
dataBuilder BloomNode Function(Map<String, String> params, dynamic data)?
Builder invoked with extracted params and resolved loader data.
final
guards List<BloomRouteGuard>
Navigation guards evaluated before this route is activated.
final
hashCode int
The hash code for this object.
no setterinherited
layout BloomNode Function(BloomNode child, Map<String, String> params)?
Layout wrapper function that encloses child route content within a shell.
final
loader Future Function(Map<String, String> params)?
Async data loader executed upon navigation before this route renders.
final
loadingFallback BloomNode Function()?
Fallback descriptor displayed within Suspense while loader is pending.
final
path String
Path pattern to match against, e.g. '/', '/users/:id', or '/docs/*'.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited