push<T, A> method

Future<T> push<T, A>(
  1. AppRoute route, {
  2. JsonMap? urlArguments,
})

Implementation

Future<T> push<T, A>(AppRoute route, {JsonMap? urlArguments}) {
  final info = routeInfos
      .singleWhereOrNull((routeInfo) => routeInfo.path == route.name);

  final useRoot = switch (info) {
    ModalRouteInfo info => info.useRootNavigator,
    _ => false,
  };

  final nestedNav = isNestedRoute(info);
  final isNested = nestedNav != null && !useRoot;

  final page = switch ((info, isNested)) {
    (null, _) => _pageFromRouteInfo<T>(
        notFoundRouteInfo,
        const NotFound(),
      ),
    (RouteInfo info, true) => _nestedPageFromRouteInfo<T>(
        info,
        route.page,
        route: route,
        urlArguments: urlArguments,
      ),
    (RouteInfo info, false) => _pageFromRouteInfo<T>(
        info,
        route.page,
        route: route,
        urlArguments: urlArguments,
      ),
  };

  if (isNested && !containsNestedRouterPage(nestedNav.key)) {
    _stack.add(_getNestedRouterPage(nestedNav));
  }

  _stack.add(page);

  notifyListeners();

  return page.popped;
}