This is an automated email from the ASF dual-hosted git repository.

Harbs pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 8090971cff Allow component routing to preserve state
8090971cff is described below

commit 8090971cffab1374e16ab95e55bcc1813acb8161
Author: Harbs <[email protected]>
AuthorDate: Wed May 13 13:17:11 2026 +0300

    Allow component routing to preserve state
---
 .../org/apache/royale/routing/ComponentRoute.as    | 25 +++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git 
a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/ComponentRoute.as
 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/ComponentRoute.as
index ccfadaa69b..0063b09608 100644
--- 
a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/ComponentRoute.as
+++ 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/ComponentRoute.as
@@ -19,6 +19,7 @@
 package org.apache.royale.routing
 {
   import org.apache.royale.core.IParent;
+  import org.apache.royale.core.IChild;
   /**
    * ComponentRoutes are declared in RouteToComponent beads.
    * This maps a base name of a route path to a component class.
@@ -33,6 +34,21 @@ package org.apache.royale.routing
      * The component class to attach to the parent. I new one is instantiated 
each time we have a new route.
      */
     public var component:Class;
+    /**
+     * Use getComponent to auto-generate the component instance.
+     * If preserveState is true, the same instance will be returned each time.
+     * Otherwise, a new instance will be created each time.
+     */
+    public function getComponent():IChild
+    {
+      if(_instance)
+        return _instance;
+      var comp:IChild = new component() as IChild;
+      if(preserveState)
+        _instance = comp;
+      return comp;
+    }
+    private var _instance:IChild;
     /**
      * This is the base name (leaf) of the route path.
      */
@@ -41,9 +57,16 @@ package org.apache.royale.routing
      * The parent to add the component to. (Defaults to the strand of the 
router.)
      */
     public var parent:IParent;
-
+    /**
+     * The title of the route, typically used for display purposes.
+     */
     public var title:String;
 
     public var defaultRoute:Boolean = false;
+    /**
+     * If true, the same instance of the component with its state will be 
preserved and returned
+     * each time this route is hit. Otherwise, a new instance will be created 
each time.
+     */
+    public var preserveState:Boolean = false;
   }
 }
\ No newline at end of file

Reply via email to