diff --git a/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php b/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php
index 33a7e6b..fbfa232 100644
--- a/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php
+++ b/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php
@@ -253,6 +253,8 @@ public function optionsSummary(&$categories, &$options) {
    */
   public function collectRoutes(RouteCollection $collection) {
     parent::collectRoutes($collection);
+    $view_id = $this->view->storage->id();
+    $display_id = $this->display['id'];
 
     $style_plugin = $this->getPlugin('style');
     // REST exports should only respond to get methods.
@@ -261,10 +263,9 @@ public function collectRoutes(RouteCollection $collection) {
     // Format as a string using pipes as a delimeter.
     $requirements['_format'] = implode('|', $style_plugin->getFormats());
 
-    // Add the new requirements to each route.
-    foreach ($collection as $route) {
-      $route->addRequirements($requirements);
-    }
+    // Add the new requirements to the route.
+    $route = $collection->get("view.$view_id.$display_id");
+    $route->addRequirements($requirements);
   }
 
   /**
