diff --git a/core/modules/system/src/Controller/SystemController.php b/core/modules/system/src/Controller/SystemController.php
index f744936..1db97a9 100644
--- a/core/modules/system/src/Controller/SystemController.php
+++ b/core/modules/system/src/Controller/SystemController.php
@@ -366,10 +366,16 @@ public static function setLinkActiveClass(array $element, array $context) {
       // Determine which of the two values matched: the exact path, or the
       // <front> special case.
       $pos_match = NULL;
-      if ($pos_current_path !== FALSE) {
+      if ($pos_front === FALSE) {
         $pos_match = $pos_current_path;
       }
-      elseif ($context['front'] && $pos_front !== FALSE) {
+      elseif ($pos_current_path === FALSE) {
+        $pos_match = $pos_front;
+      }
+      elseif ($pos_current_path < $pos_front) {
+        $pos_match = $pos_current_path;
+      }
+      else {
         $pos_match = $pos_front;
       }
 
