diff --git a/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php b/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php
index c5f2b95..d2da0fd 100644
--- a/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php
+++ b/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php
@@ -134,12 +134,17 @@ public static function setLinkActiveClass($html_markup, $current_path, $is_front
     $search_key_current_path = 'data-drupal-link-system-path="' . $current_path . '"';
     $search_key_front = 'data-drupal-link-system-path="&lt;front&gt;"';
 
-    // An active link's path is equal to the current path, so search the HTML
-    // for an attribute with that value.
     $offset = 0;
+    // There are two distinct conditions that can make a link be marked active:
+    // 1. A link has the current path in its 'data-drupal-link-system-path'
+    //    attribute.
+    // 2. We are on the front page and a link has the special '<front>' value in
+    //    its 'data-drupal-link-system-path' attribute.
     while (strpos($html_markup, $search_key_current_path, $offset) !== FALSE || ($is_front && strpos($html_markup, $search_key_front, $offset) !== FALSE)) {
       $pos_current_path = strpos($html_markup, $search_key_current_path, $offset);
-      $pos_front = strpos($html_markup, $search_key_front, $offset);
+      // Only look for links with the special '<front>' system path if we are
+      // actually on the front page.
+      $pos_front = $is_front ? strpos($html_markup, $search_key_front, $offset) : FALSE;
 
       // Determine which of the two values is the next match: the exact path, or
       // the <front> special case.
diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php
index 08152d9..27b75a0 100644
--- a/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php
+++ b/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php
@@ -326,6 +326,42 @@ public function providerTestSetLinkActiveClass() {
       5 => $front_special_link_active . ' ' . $front_path_link_active,
     ];
 
+    // Test cases to verify that links to the front page do not get the
+    // 'is-active' class when not on the front page.
+    $other_link = '<a data-drupal-link-system-path="otherpage">Other page</a>';
+    $other_link_active = '<a data-drupal-link-system-path="otherpage" class="is-active">Other page</a>';
+    $data['<front>-and-other-link-on-other-path'] = [
+      0 => $front_special_link . ' ' . $other_link,
+      1 => 'otherpage',
+      2 => FALSE,
+      3 => 'en',
+      4 => [],
+      5 => $front_special_link . ' ' . $other_link_active,
+    ];
+    $data['front-and-other-link-on-other-path'] = [
+      0 => $front_path_link . ' ' . $other_link,
+      1 => 'otherpage',
+      2 => FALSE,
+      3 => 'en',
+      4 => [],
+      5 => $front_path_link . ' ' . $other_link_active,
+    ];
+    $data['other-and-<front>-link-on-other-path'] = [
+      0 => $other_link . ' ' . $front_special_link,
+      1 => 'otherpage',
+      2 => FALSE,
+      3 => 'en',
+      4 => [],
+      5 => $other_link_active . ' ' . $front_special_link,
+    ];
+    $data['other-and-front-link-on-other-path'] = [
+      0 => $other_link . ' ' . $front_path_link,
+      1 => 'otherpage',
+      2 => FALSE,
+      3 => 'en',
+      4 => [],
+      5 => $other_link_active . ' ' . $front_path_link,
+    ];
     return $data;
   }
 
