Browse Source

* Add easy access method RouteFromURL

michael 5 years ago
parent
commit
e6d18fc1b4
1 changed files with 12 additions and 0 deletions
  1. 12 0
      packages/rtl/webrouter.pp

+ 12 - 0
packages/rtl/webrouter.pp

@@ -258,6 +258,8 @@ Type
     Function RouteRequest(Const ARouteURL : String; DoPush : Boolean = False) : TRoute;
     // Extract request path from URL. By default, returns the URL
     function GetRequestPath(const URL: String): String; virtual;
+    // Examine the URL hash and route the request. Returns the route. Use when arriving on a page do handle the initial route
+    Function RouteFromURL : String;
     // Navigation. These are easy-access methods for history.
     function GetCurrentLocation: String;
     // These use the history mechanism
@@ -644,6 +646,16 @@ begin
   Result:=SanitizeRoute(URL);
 end;
 
+function TRouter.RouteFromURL: String;
+
+begin
+  // Result:=Copy(window.location.hash,2,Length(window.location.hash)-1);
+  // Writeln('Curr ', GetCurrentLocation,' route : ',Result);
+  Result:=GetCurrentLocation;
+  if (Result<>'') then
+    Router.RouteRequest(Result,true);
+end;
+
 function TRouter.GetCurrentLocation: String;
 begin
   Result:=History.GetCurrentLocation;