BloomRouter class
Pure Dart route matching and navigation guard evaluation engine.
Operates without DOM dependencies, making it usable across VM unit tests, server-side rendering (SSR), and browser-side client routers.
Matches URL paths against a tree of BloomRoute definitions, parses parameters, evaluates BloomRouteGuard instances, and coordinates speculative route prefetching.
final router = BloomRouter([
BloomRoute('/', (params) => const Div(text: 'Home')),
BloomRoute('/users/:id', (params) => Div(text: 'User ${params['id']}')),
], notFound: BloomRoute('*', (params) => const Div(text: '404 Not Found')));
final match = router.match('/users/42?tab=profile#bio');
if (match != null) {
print(match.query['tab']); // 'profile'
print(match.fragment); // 'bio'
final node = match.build();
}
Constructors
-
BloomRouter(List<
BloomRoute> routes, {BloomRoute? notFound, bool trailing = false}) -
Creates a BloomRouter with the given
routeshierarchy and options.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- notFound → BloomRoute?
-
Fallback route definition rendered when no registered pattern matches.
final
-
routes
→ List<
BloomRoute> -
Registered route hierarchy.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- trailing → bool
-
Whether trailing slashes are stripped from paths before matching.
final
Methods
-
evaluateGuards(
BloomRoute route, String location, Map< String, String> params) → Future<GuardResult> -
Evaluates all navigation guards attached to
routein sequential order. -
match(
String path) → BloomRouteMatch? -
Matches
pathagainst registered routes. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
prefetchRoute(
String path) → Future< void> -
Prefetches route data and lazily-loaded components for
pathusing this router instance. -
resolveRedirects(
String location, {int maxRedirects = 10}) → Future< GuardResolution> -
Follows guard redirects for
locationuntil navigation is allowed. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
clearPrefetchCache(
) → void - Clears the session-level cache of prefetched paths.
-
prefetch(
String path) → Future< void> -
Prefetches route data and lazy components for
pathacross all active router instances.