Navigate back with window.history.back


I'm trying to add a simple "back" button in my app, using:


However, the script doesn't seem to work.

Does anyone have any advice on adding a back button to navigate to the user's previous URL?

Hey @kierandoyle!

Retool runs its JavaScript in a sandboxed environment so you won't have access to the parent window's history methods as you've noticed. The closest I'm thinking over here is to use something like localStorage to store the last Retool app the user visited, but that's a relatively small subset of URLs that the user might be navigating from.

Would you mind explaining more about your use case? I'm wondering if there are any other possible workarounds.

Hey folks!

As Kabirdas said, custom JS code won't have access to the window history with it being sandboxed, but it is doable with a custom component that has access to the top-level navigation!



great, thanks !

Just to document another case that came up, a setup like this will take the browser back when the goBack JS query is called from anywhere in the app. Note the custom component needs the top-level navigation flag and doesn't need to actually display anything to function.

1 Like