routes.ts 923 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { AppKernel } from "@scripts/app/AppKernel";
  2. import { UIViewID } from "@scripts/define/UIDefine";
  3. export enum RouteType {
  4. None,
  5. UI,
  6. Url,
  7. }
  8. function parseUIParams(link: string) {
  9. let res = { viewID: link, params: null }
  10. if (link.indexOf('?')) {
  11. const url = new URL(link, "https://test.com/");
  12. const viewID = url.pathname.replace(/^\//, "");
  13. let params: any = {};
  14. url.searchParams.forEach((value, key) => {
  15. params[key] = value;
  16. })
  17. res.params = params;
  18. res.viewID = viewID;
  19. }
  20. return res;
  21. }
  22. export function handleRoute(link: string) {
  23. //ui://
  24. //target://
  25. if (link.startsWith('http')) {
  26. window.open(link);
  27. return;
  28. }
  29. const { viewID, params } = parseUIParams(link);
  30. if (viewID && !!UIViewID[viewID]) {
  31. AppKernel.ui.open(viewID as UIViewID, params);
  32. return;
  33. }
  34. }