web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to persist the cur...
Power Apps
Answered

How to persist the current screen after browser refresh in Power Apps (Canvas App)?

(0) ShareShare
ReportReport
Posted on by 10

I have a Canvas app running in a web browser with the following navigation flow:

FirstLandingPage (user selects a project from a gallery) →Dashboard (loads data from related SharePoint lists/libraries based on selected project) →EvidenceScreen

 

Problem:

When a user navigates to EvidenceScreen(or any screen) and refreshes the browser (F5), the app reloads and redirects back to FirstLandingPage (StartScreen). All variables and context are lost.

 

Requirement:

After a browser refresh, the user should remain on the same screen (e.g., EvidenceScreen) with the same context (e.g., selected project and possibly selected record ID), instead of being redirected to the StartScreen.

 

Important constraints:

  • This is a Canvas app running in a web browser.

  • SaveData() / LoadData() cannot be used because they are not supported in web.

  • EvidenceScreen may depend on:

    • Selected Project ID (from FirstLandingPage)

    • Selected record ID (from Dashboard)

  • Looking for a production-grade solution suitable for enterprise web users.

 

 

How can I implement this requirement?

 

 

Attached image is FirstLandingPage

Screenshot 2026-02-25 124005.png
Categories:
I have the same question (0)
  • Suggested answer
    Sunil Kumar Pashikanti Profile Picture
    2,318 Moderator on at
     
    For a production-grade enterprise solution in Power Apps (Canvas App), the standard method to persist screen state and context (like selected project or record IDs) after a browser refresh is Deep Linking using URL parameters. 

    Since browser refreshes clear all in-memory variables, you must store your "state" in the URL itself so the app can read it back upon reloading.
     
    References:
     
    âś… If this answer helped resolve your issue, please mark it as Accepted so it can help others with the same problem.
    👍 Feel free to Like the post if you found it useful.
     
  • MA-25020705-0 Profile Picture
    10 on at
    Thank you @Sunil Kumar Pashikanti for your reply,
    but the method you have describe will not be suitable for me as i have embedded my PowerApps in Powerpages through iFrame, is there any other way to achieve the same?
     
  • Verified answer
    WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    I am not sure deep linking is the solution here as every user is going to have a different screen to return to, so that is going to have to be stored somewhere. Being pragmatic, the obvious solution I would have thought is tell tell users not to refresh their browser (they will learn quickly), however if you really need this, then you would write to a control file every time a user changed screens with their name and the screen they are going to.
    Patch(
       ControlList,
       Coslesce(
          Lookup(
             ControlList,
             EmailField = User().Email
          ),
          Defaults(ControlList)
       ),
       {
          EmailField: User().Email,
          ScreenField: "YourScreenName"
       }
    )
    They would need to exit property (not close the tab) if you wanted to clear this.
     
    Then at App StartScreen
    With(
       {
          _Screen:
          LookUp(
             ControlList,
             EmailField = User().Email
          ).ScreenField
       },
       Switch(
          _Screen,
          "Screen1",
          Screen1,
          "Screen2",
          Screen2,
          "Screen3",
          Screen3,
          YourLandingScreen
       )
    )
         
    So if there is a screen name in the control file belonging to the user, then the app would navigate to that screen, otherwise go to your default screen.
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog
    Practical Power Apps    LinkedIn  
     
  • Sunil Kumar Pashikanti Profile Picture
    2,318 Moderator on at
     
    Try this.
     
    What we will do here:
    Power Apps → send RecordId to Power Pages
    Power Pages → insert RecordId into browser URL
    Power Pages → rewrite iframe src using Liquid
    Power Apps → read RecordId using Param()
     
    Step 1: Push the RecordId to js custom function. Replace js with javascript
    Set(varID, ThisItem.ID);
    Launch("
    js:
    window.postMessage
    ({ recordid: " & ThisItem.ID & " },'*')");
    Navigate(EvidenceScreen);

    Step 2: Add below JS in the same power page to capture the pushed recordId, this inserts the recordId in the browser URL, and also adds it to iFrame src url. If the below js code does not work, just replace it with a js code that captures the browser url parameter and assign it to iFrame src. Add the below function in script tag.

    (function() {
      const iframeId = "MyAppFrame"; // MUST match the iframe id below
      const allowedOrigins = [
        "https://apps.powerapps.com",         // Power Apps host
        location.origin                       // Your portal origin (safety default)
      ];
      function isAllowedOrigin(origin) {
        // Relax this list if needed; keeping '*' is easiest but unsafe
        return allowedOrigins.some(o => origin.startsWith(o));
      }
      window.addEventListener("message", function (e) {
        try {
          if (!e || !e.data) return;
          // SECURITY: optionally check origin
          // if (!isAllowedOrigin(e.origin)) return;
          const recId = e.data.recordId ?? e.data.RecordId ?? e.data.recordid;
          if (!recId) return;
          // Update browser URL (no page reload)
          const url = new URL(window.location.href);
          url.searchParams.set("RecordId", recId);
          history.replaceState({}, "", url.toString());
          // Update iFrame src so embedded app receives Param("RecordId")
          const iframe = document.getElementById(iframeId);
          if (!iframe) return;
          const base = "https://apps.powerapps.com/play/<appid>";
          const qs = [
            "RecordId=" + encodeURIComponent(recId),
            "hidenavbar=true",       // optional UX
            "source=portal"          // optional marker
          ].join("&");
          // Preserve existing hash if present
          const hash = iframe.src.includes("#") ? iframe.src.split("#")[1] : "";
          iframe.src = base + "?" + qs + (hash ? "#" + hash : "");
        } catch (err) {
          console.error("Deep-link handler error:", err);
        }
      }, false);
    })();

    Step 3: Modify your iframe as below to capture the RecordId
    <iframe
       id="myiframe"
       width="100%" 
       height="900px"
       src="https://apps.powerapps.com/play/<appid>?recordId={{ request.params['recordId'] }}"
       frameborder="0">
    </iframe>
     
    Step 4: Update the StartScreen/OnStart (whatever applicable) property for param check and navigation to EvidenceScreen if RecordId available, something like this:

    // App.StartScreen
    If(
        !IsBlank(Param("RecordId")),
        EvidenceScreen,   // go straight to Details
        LandingScreen     // default
    )
     
    If it works, then you will have an issue of navigating back to landing page. You need to clear the url (recordId) from the browser, otherwise you will be always navigated to evidence page.
     
    Hope it works!
     
     
     
     
  • MA-25020705-0 Profile Picture
    10 on at
     
     
     
    It Worked!!!
     
     
    thank you for this simple and working solution.
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    I am glad this suited your requirements - things do not need be always complex.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard