pop static method

void pop(
  1. GoRouter router, {
  2. int? level,
  3. List<FeatureNavigationConfiguration>? allFeatures,
})

Closes level and everything above it. If level is omitted, it's resolved from the current route name (via allFeatures) or, failing that, from the path depth.

Implementation

static void pop(GoRouter router, {int? level, List<FeatureNavigationConfiguration>? allFeatures}) {
  final currentState = router.state;
  final currentUri = currentState.uri;
  final currentPath = currentUri.path;

  int? levelFromRouteName;
  if (allFeatures != null && level == null) {
    final routeName = currentState.name;
    levelFromRouteName = _getLevelByRouteName(routeName, allFeatures);
  }

  final targetPath = calculateTargetPathForPop(
    currentPath: currentPath,
    level: level,
    levelFromRouteName: levelFromRouteName,
    pathDepth: PathUtils.getPathDepth(currentPath),
  );

  if (targetPath == null) {
    return;
  }

  final newUri = Uri(
    path: targetPath,
    queryParameters: currentUri.queryParameters.isEmpty ? null : currentUri.queryParameters,
    fragment: currentUri.fragment.isEmpty ? null : currentUri.fragment,
  );

  router.go(newUri.toString(), extra: currentState.extra);
}