Get node from url in drupal 8

foreach (\Drupal::routeMatch()->getParameters() as $entity) {
  if ($entity instanceof \Drupal\Core\Entity\EntityInterface) {
    // here $entity is your object
  }
}

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!