diff --git a/src/EventSubscriber/RouteParamContext.php b/src/EventSubscriber/RouteParamContext.php
index ea19129..5d0bdd8 100644
--- a/src/EventSubscriber/RouteParamContext.php
+++ b/src/EventSubscriber/RouteParamContext.php
@@ -16,6 +16,7 @@
 use Drupal\page_manager\Event\PageManagerEvents;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 use Symfony\Component\HttpFoundation\RequestStack;
+use Symfony\Component\Routing\Route;
 
 /**
  * Sets values from the route parameters as a context.
@@ -63,7 +64,7 @@ public function onPageContext(PageManagerContextEvent $event) {
     $routes = $this->routeProvider->getRoutesByPattern($executable->getPage()->getPath())->all();
     $route = reset($routes);
 
-    if ($route_contexts = $route->getOption('parameters')) {
+    if ($route instanceof Route && $route_contexts = $route->getOption('parameters')) {
       foreach ($route_contexts as $route_context_name => $route_context) {
         // Skip this parameter.
         if ($route_context_name == 'page_manager_page') {
diff --git a/tests/src/Unit/RouteParamContextTest.php b/tests/src/Unit/RouteParamContextTest.php
index cfd0dfc..d19559f 100644
--- a/tests/src/Unit/RouteParamContextTest.php
+++ b/tests/src/Unit/RouteParamContextTest.php
@@ -82,4 +82,32 @@ public function testOnPageContext() {
     $route_param_context->onPageContext($this->event);
   }
 
+  /**
+   * @covers ::onPageContext
+   */
+  public function testOnPageContextEmptyCollection() {
+    $collection = new RouteCollection();
+    $route_provider = $this->prophesize(RouteProviderInterface::class);
+    $route_provider->getRoutesByPattern('/test_route')->willReturn($collection);
+
+    $request = new Request();
+    $request_stack = new RequestStack();
+    $request_stack->push($request);
+
+    $page = $this->prophesize(PageInterface::class);
+    $this->executable->expects($this->once())
+      ->method('getPage')
+      ->will($this->returnValue($page->reveal()));
+    $page->getPath()->willReturn('/test_route');
+
+    $this->executable->expects($this->never())
+      ->method('addContext');
+
+    // Set up a request with one of the expected parameters as an attribute.
+    $request->attributes->add(['foo' => 'banana']);
+
+    $route_param_context = new RouteParamContext($route_provider->reveal(), $request_stack);
+    $route_param_context->onPageContext($this->event);
+  }
+
 }
