Retool doesn't return to the default page when reloading

Hi,

I’m having an issue with reloading the app. When I press F5 or Ctrl+F5, the app stays on the screen I’m on and doesn’t go to the default screen.

I have tried adding several scripts in Preloaded JS, but for example, “utils” is not available. Does anyone know how to solve this issue?

Thank you in advance.

1 Like

@Albertoerto

If you always want the app to open on the default page:

:backhand_index_pointing_right: Open the app using this format:

https://yourcompany.retool.com/apps/Your_App_Name

or

you must use “window.retool” instead of “utils”, because utilities like utils.navigateTo() are NOT available in Preloaded JS.

Use this code in Preloaded JS:

window.onload = () => {
  // Change 'Home' to the name of your default page
  window.retool.navigateToApp('Your_App_Name', {
    pageName: 'Home'
  });
};

:fire: Notes:

  • Replace "Your_App_Name" with your exact app name.

  • Replace "Home" with your default page name.

  • This runs only when app first loads, including F5 / Ctrl+F5.

HI @Anuragsinh,

I tried what you suggested, but the same thing keeps happening. When I'm on another screen and press F5 or Ctrl+F5, it stays on the screen I'm on and doesn't return to the main screen.

I don't understand why this is happening, but none of the options I try work. Could it be a bug?

Thank you for your attention.

Hey @Albertoerto, thanks for reporting this! Have you tried setting it up directly in the Pages tab like this?

If you can share a quick screenshot of what you currently have in the Pages tab, that would help me see if anything looks off. Thanks!

Hello! Yes, I already have the page set as my home page, but when I press F5, it doesn't return to the previous page, it reloads the screen I was on before pressing F5.

Thank you for your attention.

Hey @Albertoerto, sorry I totally missed this in your first post, I’m on a Mac myself haha. On Windows, F5 just refreshes the current page, so it won’t navigate to another page or reset anything, which is why you’re not seeing it change pages.

Your default page should load automatically when you first land on the app URL. Is that what you are seeing when you go to your site?

Hey @Albertoerto happy new year! :partying_face: Just checking in with you, did you get a chance to look at the post above?

Hello @ChiEn happy new year! :confetti_ball: I use Windows, and if I press Ctrl+F5, it refreshes the current page but deletes the variables, so if I am inside a record and not on the main screen, all fields are left blank because when the “selectedRecord” variable is emptied, the query finds nothing.

That's where the problem lies. If it's not possible to return to the home page, is there any way to persist the variable so that it doesn't remain empty when the page is refreshed?

Sorry for not responding sooner.

Hey @Albertoerto, thanks for clarifying! I understand what you’re trying to do now! :slight_smile:

If your goal is for a refresh (Ctrl+F5) to always bring the user back to the homepage, the most reliable way to do this is to run logic on page load rather than in Preloaded JS.

You can create a JS query that runs on page load and checks whether your state variable (for example, selectedRecord) exists. If it’s missing or empty, you can force navigation back to the homepage using utils.openPage. Here's the docs about utils.openPage.

Let me know if you need any help to set this up! :folded_hands:t3:

1 Like

Hello!!

Perfect!This really works.

Thank you very much for your help.

1 Like

Perfect, so glad to hear that! :smiley:
Feel free to create a new topic if you have any other questions, and have fun building! :building_construction: