How to get the node from the url referer? I have a custom entity named Application that has an Entity Reference field named Product.

When I am on an Apllication page and click on a Product to see it, I would like to know that I come from the Application page and know its ID.

This would allow me to display information from the Application page on the Product page.

But how to do it ?
This method works for me:

use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Url;
// Getting the referer.
$request = \Drupal::request();
$referer = $request-&gt;headers-&gt;get('referer');
// Getting the base url.
$base_url = Request::createFromGlobals()-&gt;getSchemeAndHttpHost();
// Getting the alias or the relative path.
$alias = substr($referer, strlen($base_url));
// Getting the node.
$params = Url::fromUri("internal:" . $alias)-&gt;getRouteParameters();
$entity_type = key($params);
$node = \Drupal::entityTypeManager()-&gt;getStorage($entity_type)-&gt;load($params[$entity_type]);

//to use dpm you need the devel module
dpm($node-&gt;id());
dpm($node-&gt;title-&gt;value);