Back button issue in browser from cloak page

We are using keycloak login and registration page in our Application. When we coming to keycloak pages from our app and clicking on back button in browser then it is not redirecting to previous URL, rathar than it is visiting to second last previous URL. can you please look into it and help me to redirect to previsous URL


We are having the same issue. Our current setup is…

  • React application using NextJS
  • Standalone Keycloak server

We have set things up with the default settings using an Authorization Code Flow.

When we use the keycloak-js library to call keycloak.login(), it directs to Keycloak correctly. But, if the user clicks the Back button in the browser, they are not taken to the previous page, but to the the page that was in the browser history before the previous page.

I have a feeling that the keycloak-js library is re-writing the browser history.

This also happens if we call keycloak.register().

I have not found a workaround yet. Would like to hear from the keycloak-js team about this.


Hey, did you find any solution for this? I have the same issue in my Ionic project when using the device hardware back button. It is also strange, that the promise returned by the login method is throwing an error. Any ideas how decide if it was a ‘real’ error or a backnavigation?