drupal 8 get node url code example
Example 1: drupal 8 get page node
// Get page node.
$node = \Drupal::routeMatch()->getParameter('node');
// Get page entity.
$params = \Drupal::routeMatch()->getParameters()->all();
$entity = reset($params);
Example 2: drupal 8 get url from node entity
$entity->toUrl()->toString();