title: How to redirect to the last visited page in Grails app?
body: <p>I am a newbie in Grails and I am struggling with many simple issues.</p>
  
  <p>For instance, I haven't managed to find a proper way to go back to the last visited page when I login/logout from a template view that is displayed on the top layout of the page.</p>
  
  <p>My last attempt at solving this problem was to save the ${params.controller} and ${params.action} in the parameters sent to the logout action and redirect thereafter. Well...even this failed.
  Here is the gsp snippet:</p>
  
  <pre><code>&lt;g:link controller="user" action="logout" params="[currentController: ${params.controller}, currentAction: ${params.action}]"&gt;Logout&lt;/g:link&gt;
  </code></pre>
  
  <p>This last code line throws the following exception:</p>
  
  <pre><code>ERROR errors.GrailsExceptionResolver  - Error evaluating expression [[currentController: ${params.controller}, currentAction: ${params.action}]]
  </code></pre>
  
  <p>So my questions are:</p>
  
  <p>1 - How can I reload the last visited page after a login/logout action ?</p>
  
  <p>2 - Why do I have an exception from my code above?</p>
  
  <p>Thank You  </p>
  
  <p>EDIT :
  Concerning question #2, it seems that the following code is working:</p>
  
  <pre><code>&lt;g:link controller="user" action="logout" params="[currentController: params.controller, currentAction: params.action]"&gt;Logout&lt;/g:link&gt;
  </code></pre>
  
  <p>But I don't really understand the reason...</p>
  
  <p>EDIT2 : 
  I have also found out a solution for redirecting to the last visited page:</p>
  
  <pre><code>redirect(url: request.header('referer'))
  </code></pre>
  
  <p>But unfortunately when doing this after login, the contents rendered in my page are duplicated. Any idea or any other safe solution?</p>