createLinkToLocation method

Future<Uri> createLinkToLocation(
  1. String location, {
  2. String? title,
  3. String? description,
  4. String? imageUrl,
  5. FFXLinkCampaign campaign = FFXLinkCampaign.empty,
  6. String? name,
  7. bool forceRedirect = false,
})

createLink for a router location (/product?id=42), such as GoRouterState.of(context).uri.toString(). utm_* keys in its query are left out: they say how this visitor arrived, not what the page is.

Implementation

Future<Uri> createLinkToLocation(
  String location, {
  String? title,
  String? description,
  String? imageUrl,
  FFXLinkCampaign campaign = FFXLinkCampaign.empty,
  String? name,
  bool forceRedirect = false,
}) async {
  final uri = Uri.tryParse(location);
  if (uri == null || uri.hasScheme || uri.hasAuthority) {
    throw clientValidationError(
      '"$location" is not a router location.',
      'Pass a location such as /product?id=42, without a scheme or host.',
    );
  }
  return createLink(
    path: uri.path.isEmpty ? '/' : uri.path,
    parameters: {
      for (final MapEntry(:key, :value) in uri.queryParameters.entries)
        if (!isUtmKey(key)) key: value,
    },
    title: title,
    description: description,
    imageUrl: imageUrl,
    campaign: campaign,
    name: name,
    forceRedirect: forceRedirect,
  );
}