paramsForUrl method

RouterParams<O, P> paramsForUrl(
  1. String url
)

Takes a url (i.e. "/users/16/hello") and breaks it into a {@link RouterParams} instance where each of the parameters (like ":id") has been parsed.

Implementation

RouterParams<O, P> paramsForUrl(String url) {
  final cleanedUrl = VoyagerUtils.cleanUrl(url);

  final parsedUri = Uri.parse("http://tempuri.org/" + cleanedUrl);

  final urlPath = parsedUri.path.substring(1);

  if (_cachedRoutes[cleanedUrl] != null) {
    return _cachedRoutes[cleanedUrl]!;
  }

  final givenParts = urlPath.split("/");

  // first check for matching non wildcard routes just to avoid being shadowed
  // by more generic wildcard routes
  var routerParams = _checkRouteSet(_routes.entries, givenParts, false);

  // still null, try matching to any wildcard routes
  routerParams ??= _checkRouteSet(_wildcardRoutes.entries, givenParts, true);

  if (routerParams == null) {
    throw RouteNotFoundException("No route found for url $url");
  }

  routerParams.openParams.addAll(parsedUri.queryParameters);

  _cachedRoutes[cleanedUrl] = routerParams;
  return routerParams;
}