diff --git a/core/modules/user/src/Form/UserLoginForm.php b/core/modules/user/src/Form/UserLoginForm.php
index 54a3d4280f..97bac7b9f4 100644
--- a/core/modules/user/src/Form/UserLoginForm.php
+++ b/core/modules/user/src/Form/UserLoginForm.php
@@ -137,7 +137,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
     $form['#validate'][] = '::validateFinal';
 
     $this->renderer->addCacheableDependency($form, $config);
-
+    $form['#cache']['max-age'] = -1;
     return $form;
   }
 
@@ -153,10 +153,16 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
 
     // A destination was set, probably on an exception controller.
     if (!$this->getRequest()->request->has('destination')) {
-      $form_state->setRedirect(
-        'entity.user.canonical',
-        ['user' => $account->id()]
-      );
+      $destination = $this->getRefererDestination();
+      if ($destination) {
+        $this->getRequest()->query->set('destination', $destination);
+      }
+      else {
+        $form_state->setRedirect(
+          'entity.user.canonical',
+          ['user' => $account->id()]
+        );
+      }
     }
     else {
       $this->getRequest()->query->set('destination', $this->getRequest()->request->get('destination'));
@@ -281,4 +287,18 @@ public function validateFinal(array &$form, FormStateInterface $form_state) {
     }
   }
 
+  /**
+   * Sets an error if supplied username has been blocked.
+   */
+  public function getRefererDestination() {
+    $referer = $this->getRequest()->server->get('HTTP_REFERER');
+    $parsed_url = parse_url($referer);
+    $query_params = [];
+    if (isset($parsed_url['query'])) {
+      parse_str($parsed_url['query'], $query_params);
+    }
+    $destination = isset($query_params['destination']) ? $query_params['destination'] : NULL;
+    return $destination;
+  }
+
 }
