RouteDefinition.defer constructor

RouteDefinition.defer({
  1. String? path,
  2. required LoadComponentAsync loader,
  3. FutureOr<void> prefetcher(
    1. RouterState
    )?,
  4. bool? useAsDefault,
  5. dynamic additionalData,
  6. RoutePath? routePath,
})

Define a route from path that uses loader to resolve a component.

Can be used to prefetch/initialize, such as loading a deferred library:

import 'contact_view.template.dart' deferred as contact_view;

Future<ComponentFactory> loadContentView() async {
  await contact_view.loadLibrary();
  return contact_view.ContactViewComponentNgFactory;
}

Then create a RouteDefinition that uses loadContentView:

new RouteDefinition.defer('contact', loadContactView);

An optional prefetcher can be specified to prefetch additional resources. The prefetcher is passed a partial RouterState that represents the match so far from the root matching route. It's possible that the prefetcher will be invoked during route resolution, even if its route doesn't fully match, or is prevented from activating. The prefetcher is run concurrently with loader. If the prefetcher returns a Future, its result is awaited before the route is initialized. If the result of the prefetcher doesn't need to be awaited before activating the route, it should return void.

At most one route may be set to useAsDefault, which means it will be automatically inferred to be in use if there are no matching routes for a given outlet.

Implementation

factory RouteDefinition.defer({
  String? path,
  required LoadComponentAsync loader,
  FutureOr<void> Function(RouterState)? prefetcher,
  bool? useAsDefault,
  dynamic additionalData,
  RoutePath? routePath,
}) = DeferredRouteDefinition._;