getPath method Null safety

  1. @override
String getPath()

Returns the active path in the browser.


String getPath() {
  // the hash value is always prefixed with a `#`
  // and if it is empty then it will stay empty
  final String path = _platformLocation.hash;
  assert(path.isEmpty || path.startsWith('#'));

  // We don't want to return an empty string as a path. Instead we default to "/".
  if (path.isEmpty || path == '#') {
    return '/';
  // At this point, we know [path] starts with "#" and isn't empty.
  return path.substring(1);