demorouter.pas 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. program demorouter;
  2. {$mode objfpc}
  3. {$H+}
  4. uses web, classes, js, sysutils, webrouter, frmdemo;
  5. Procedure ShowForm (URl : String; aRoute : TRoute; Params: TStrings);
  6. Var
  7. s : string;
  8. begin
  9. document.body.innerHTML:='';
  10. S:=aRoute.URLPattern;
  11. if (Copy(S,Length(S),1)='/') then
  12. S:=Copy(S,1,Length(S)-1);
  13. Delete(S,1,4);
  14. TDemoForm.Create(StrToIntDef(S,1));
  15. end;
  16. begin
  17. // Leave this if you want to use the hash history.
  18. // This will work in all cases.
  19. Router.InitHistory(hkHash);
  20. // Uncomment this if you want to use the HTML5 pushstate history mechanism.
  21. // Note that you must server the files from a webserver then.
  22. // See also the histsrv.js node server which will "correctly" serve all files.
  23. // Router.InitHistory(hkHTML5,'http://localhost:3000/');
  24. Router.RegisterRoute('form1',@ShowForm,True);
  25. Router.RegisterRoute('form2',@ShowForm,False);
  26. Router.RegisterRoute('form3',@ShowForm,False);
  27. Router.RegisterRoute('form4',@ShowForm,False);
  28. Router.RegisterRoute('form5',@ShowForm,False);
  29. Router.Push('form1');
  30. end.