You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ha...@apache.org on 2026/06/21 12:52:31 UTC
(royale-asjs) branch develop updated: Routing supports replaceState
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 b77436f703 Routing supports replaceState
b77436f703 is described below
commit b77436f70318a6494762e5039d8e9e660c59599c
Author: Harbs <ha...@in-tools.com>
AuthorDate: Sun Jun 21 15:52:25 2026 +0300
Routing supports replaceState
---
.../org/apache/royale/routing/BrowserRouter.as | 20 +++++++++++++++++++-
.../royale/org/apache/royale/routing/HashRouter.as | 20 +++++++++++++++++++-
.../royale/org/apache/royale/routing/IRouter.as | 1 +
.../royale/org/apache/royale/routing/Router.as | 22 ++++++++++++++++++++--
4 files changed, 59 insertions(+), 4 deletions(-)
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/BrowserRouter.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/BrowserRouter.as
index 408491b15f..91d5327801 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/BrowserRouter.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/BrowserRouter.as
@@ -189,6 +189,22 @@ package org.apache.royale.routing
* @productversion Royale 0.9.8
*/
public function setState():void
+ {
+ commitState(false);
+ }
+ /**
+ * Replaces the current state in the browsing history
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 1.0.0
+ */
+ public function replaceState():void
+ {
+ commitState(true);
+ }
+
+ private function commitState(replace:Boolean):void
{
COMPILE::JS
{
@@ -200,7 +216,9 @@ package org.apache.royale.routing
if(!ev.defaultPrevented)
{
path += ev.value;
- window.history.pushState(stateEv.value,_routeState.title,path);
+ replace ?
+ window.history.replaceState(stateEv.value,_routeState.title,path):
+ window.history.pushState(stateEv.value,_routeState.title,path);
sendStrandEvent(this,"stateSet");
}
}
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/HashRouter.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/HashRouter.as
index 8f183da004..188e5918dd 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/HashRouter.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/HashRouter.as
@@ -200,6 +200,22 @@ package org.apache.royale.routing
* @productversion Royale 0.9.8
*/
public function setState():void
+ {
+ commitState(false);
+ }
+ /**
+ * Replaces the current state in the browsing history
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 1.0.0
+ */
+ public function replaceState():void
+ {
+ commitState(true);
+ }
+
+ private function commitState(replace:Boolean):void
{
COMPILE::JS
{
@@ -211,7 +227,9 @@ package org.apache.royale.routing
if(!ev.defaultPrevented)
{
hash += ev.value;
- window.history.pushState(stateEv.value,_routeState.title,hash);
+ replace ?
+ window.history.replaceState(stateEv.value,_routeState.title,hash):
+ window.history.pushState(stateEv.value,_routeState.title,hash);
sendStrandEvent(this,"stateSet");
}
}
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/IRouter.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/IRouter.as
index 2898431b65..f275d25ba6 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/IRouter.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/IRouter.as
@@ -26,5 +26,6 @@ package org.apache.royale.routing
function set routeState(state:RouteState):void;
function get host():IStrand;
function setState():void;
+ function replaceState():void;
}
}
\ No newline at end of file
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/Router.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/Router.as
index 4c0205f9d0..32b52d2b37 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/Router.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/Router.as
@@ -167,6 +167,22 @@ package org.apache.royale.routing
* @productversion Royale 0.9.7
*/
public function setState():void
+ {
+ commitState(false);
+ }
+ /**
+ * Replaces the current state in the browsing history
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.7
+ */
+ public function replaceState():void
+ {
+ commitState(true);
+ }
+
+ private function commitState(replace:Boolean):void
{
COMPILE::JS
{
@@ -178,8 +194,10 @@ package org.apache.royale.routing
if(!ev.defaultPrevented)
{
hash += ev.value;
- window.history.pushState(stateEv.value,_routeState.title,hash);
- sendStrandEvent(this,"stateSet");
+ replace ?
+ window.history.replaceState(stateEv.value,_routeState.title,hash):
+ window.history.pushState(stateEv.value,_routeState.title,hash);
+ sendStrandEvent(this,"stateSet");
}
}
}