How to get the raw value of the url in a link field
Instead of rendering the URL object with toString() use the method Url::getInternalPath:

$url = $link-&gt;getUrl();
if ($url-&gt;isRouted()) {
  $path = $url-&gt;getInternalPath();
}