setInitialRoutePath method

  1. @override
Future<void> setInitialRoutePath(
  1. Destination configuration
)
override

Called by the Router at startup with the structure that the RouteInformationParser obtained from parsing the initial route.

This should configure the RouterDelegate so that when build is invoked, it will create a widget tree that matches the initial route.

By default, this method forwards the configuration to setNewRoutePath.

Consider using a SynchronousFuture if the result can be computed synchronously, so that the Router does not need to wait for the next microtask to schedule a build.

See also:

Implementation

@override
Future<void> setInitialRoutePath(Destination configuration) async {
  final DBPage? newPage = await pageBuilders.getPage(configuration);

  // This is called mostly for deep linking or web navigation
  // if the path is unknown and can't be handle we just ignore it
  // or we could return the user to a 404 page.
  if (newPage != null) {
    // Setting a initial route we need clear up the the stack
    // and reset the history to start with the requested route.
    _pages.clear();

    final List<Destination>? newStack = configuration.metadata.history;

    // If the new destination has a history then we need to recreate that
    // stack before add the new page.
    if (newStack != null) {
      final List<DBPage> newPages = await _pageBuilders.createPages(newStack);

      _pages.addAll(newPages);
    }
    _pages.add(newPage);
  }
}