prepareExternalUrl method

  1. @override
String prepareExternalUrl(
  1. String internalUrl
)
override

Given a path that's internal to the app, create the external url that will be used in the browser.

Implementation

@override
String prepareExternalUrl(String internalUrl) {
  // It's convention that if the hash path is empty, we omit the `#`; however,
  // if the empty URL is pushed it won't replace any existing fragment. So
  // when the hash path is empty, we still return the location's path and
  // query.
  final String hash;
  if (internalUrl.isEmpty || internalUrl == '/') {
    // Let's not add the hash at all when the app is in the home page. That
    // way, the URL of the home page is cleaner.
    //
    // See: https://github.com/flutter/flutter/issues/127608
    hash = '';
  } else {
    hash = '#$internalUrl';
  }
  return '${_platformLocation.pathname}${_platformLocation.search}$hash';
}