How do I use Path Matcher for front page? I have used the following code in a Drupal 8 theme file.

$current_path = \Drupal::request()-&gt;getRequestUri();
$path_alias = Unicode::strtolower(\Drupal::service('path.alias_manager')-&gt;getAliasByPath($current_path));
$visiblity = \Drupal::service('path.matcher')-&gt;matchPath($path_alias, $pages);


$pages contains values like '&lt;front&gt;' or '/blog'.

$visiblity is set to FALSE for /, but to TRUE for /node; Both are the front page. 

What is the wrong with my code?
Your code is assuming that the request URI for / will retrieve /node on the getAliasByPath() method call. It won't. Setting the Drupal front page isn't the same as setting a path alias in the Path module.

Use the following code, which will return Drupal's internal /node path even on / requests.

$current_path = \Drupal::service('path.current')-&gt;getPath();