reactive-route 0.0.1-alpha.33 → 0.0.1-alpha.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/adapters/mobx-preact.cjs +1 -0
  2. package/adapters/mobx-preact.d.ts.map +1 -1
  3. package/adapters/mobx-preact.mjs +1 -0
  4. package/adapters/mobx-react.cjs +1 -0
  5. package/adapters/mobx-react.d.ts.map +1 -1
  6. package/adapters/mobx-react.mjs +1 -0
  7. package/adapters/mobx-solid.cjs +1 -0
  8. package/adapters/mobx-solid.d.ts.map +1 -1
  9. package/adapters/mobx-solid.mjs +1 -0
  10. package/adapters/solid.cjs +1 -0
  11. package/adapters/solid.d.ts.map +1 -1
  12. package/adapters/solid.mjs +1 -0
  13. package/adapters/vue.cjs +1 -0
  14. package/adapters/vue.d.ts.map +1 -1
  15. package/adapters/vue.mjs +1 -0
  16. package/core/createRouter.d.ts.map +1 -1
  17. package/core/createRoutes.d.ts +6 -8
  18. package/core/createRoutes.d.ts.map +1 -1
  19. package/core/types/TypeCurrentRoute.d.ts +1 -0
  20. package/core/types/TypeCurrentRoute.d.ts.map +1 -1
  21. package/core/types/TypeRouter.d.ts +8 -4
  22. package/core/types/TypeRouter.d.ts.map +1 -1
  23. package/core/utils/constants.d.ts +0 -2
  24. package/core/utils/constants.d.ts.map +1 -1
  25. package/core/utils/dynamic.d.ts +1 -1
  26. package/core/utils/dynamic.d.ts.map +1 -1
  27. package/core/utils/findRouteByPathname.d.ts.map +1 -1
  28. package/core/utils/getDynamicValues.d.ts.map +1 -1
  29. package/core/utils/getQueryValues.d.ts.map +1 -1
  30. package/core/utils/replaceDynamicValues.d.ts.map +1 -1
  31. package/core/utils/routerSetLoadedComponent.d.ts.map +1 -1
  32. package/index.cjs +57 -42
  33. package/index.mjs +57 -42
  34. package/package.json +1 -1
  35. package/preact/Router.d.ts +1 -1
  36. package/preact/Router.d.ts.map +1 -1
  37. package/preact/index.cjs +3 -7
  38. package/preact/index.mjs +3 -7
  39. package/react/Router.d.ts +1 -3
  40. package/react/Router.d.ts.map +1 -1
  41. package/react/index.cjs +4 -7
  42. package/react/index.mjs +5 -8
  43. package/solid/Router.d.ts.map +1 -1
  44. package/solid/index.cjs +1 -1
  45. package/solid/index.mjs +1 -1
  46. package/vue/index.cjs +0 -0
  47. package/vue/index.mjs +0 -0
  48. package/core/utils/addNames.d.ts +0 -8
  49. package/core/utils/addNames.d.ts.map +0 -1
@@ -41,3 +41,4 @@ var adapters = {
41
41
  },
42
42
  makeObservable: import_mobx.observable
43
43
  };
44
+ /* v8 ignore if -- @preserve */
@@ -1 +1 @@
1
- {"version":3,"file":"mobx-preact.d.ts","sourceRoot":"","sources":["../../packages/adapters/mobx-preact.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAO,MAAM,QAAQ,EAAE,YAetB,CAAC"}
1
+ {"version":3,"file":"mobx-preact.d.ts","sourceRoot":"","sources":["../../packages/adapters/mobx-preact.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAO,MAAM,QAAQ,EAAE,YAgBtB,CAAC"}
@@ -20,3 +20,4 @@ var adapters = {
20
20
  export {
21
21
  adapters
22
22
  };
23
+ /* v8 ignore if -- @preserve */
@@ -41,3 +41,4 @@ var adapters = {
41
41
  },
42
42
  makeObservable: import_mobx.observable
43
43
  };
44
+ /* v8 ignore if -- @preserve */
@@ -1 +1 @@
1
- {"version":3,"file":"mobx-react.d.ts","sourceRoot":"","sources":["../../packages/adapters/mobx-react.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAO,MAAM,QAAQ,EAAE,YAetB,CAAC"}
1
+ {"version":3,"file":"mobx-react.d.ts","sourceRoot":"","sources":["../../packages/adapters/mobx-react.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAO,MAAM,QAAQ,EAAE,YAgBtB,CAAC"}
@@ -20,3 +20,4 @@ var adapters = {
20
20
  export {
21
21
  adapters
22
22
  };
23
+ /* v8 ignore if -- @preserve */
@@ -40,3 +40,4 @@ var adapters = {
40
40
  makeObservable: import_mobx.observable,
41
41
  immediateSetComponent: true
42
42
  };
43
+ /* v8 ignore if -- @preserve */
@@ -1 +1 @@
1
- {"version":3,"file":"mobx-solid.d.ts","sourceRoot":"","sources":["../../packages/adapters/mobx-solid.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAO,MAAM,QAAQ,EAAE,YAetB,CAAC"}
1
+ {"version":3,"file":"mobx-solid.d.ts","sourceRoot":"","sources":["../../packages/adapters/mobx-solid.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAO,MAAM,QAAQ,EAAE,YAgBtB,CAAC"}
@@ -19,3 +19,4 @@ var adapters = {
19
19
  export {
20
20
  adapters
21
21
  };
22
+ /* v8 ignore if -- @preserve */
@@ -43,3 +43,4 @@ var adapters = {
43
43
  },
44
44
  makeObservable: import_store.createMutable
45
45
  };
46
+ /* v8 ignore next -- @preserve */
@@ -1 +1 @@
1
- {"version":3,"file":"solid.d.ts","sourceRoot":"","sources":["../../packages/adapters/solid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C,eAAO,MAAM,QAAQ,EAAE,YAmBtB,CAAC"}
1
+ {"version":3,"file":"solid.d.ts","sourceRoot":"","sources":["../../packages/adapters/solid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C,eAAO,MAAM,QAAQ,EAAE,YAoBtB,CAAC"}
@@ -22,3 +22,4 @@ var adapters = {
22
22
  export {
23
23
  adapters
24
24
  };
25
+ /* v8 ignore next -- @preserve */
package/adapters/vue.cjs CHANGED
@@ -38,3 +38,4 @@ var adapters = {
38
38
  makeObservable: import_vue.reactive,
39
39
  immediateSetComponent: true
40
40
  };
41
+ /* v8 ignore if -- @preserve */
@@ -1 +1 @@
1
- {"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../../packages/adapters/vue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,eAAO,MAAM,QAAQ,EAAE,YAatB,CAAC"}
1
+ {"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../../packages/adapters/vue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,eAAO,MAAM,QAAQ,EAAE,YActB,CAAC"}
package/adapters/vue.mjs CHANGED
@@ -17,3 +17,4 @@ var adapters = {
17
17
  export {
18
18
  adapters
19
19
  };
20
+ /* v8 ignore if -- @preserve */
@@ -1 +1 @@
1
- {"version":3,"file":"createRouter.d.ts","sourceRoot":"","sources":["../../packages/core/createRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAWhD,wBAAgB,YAAY,CAC1B,OAAO,SAAS,MAAM,CAAC,MAAM,GAAG,UAAU,GAAG,eAAe,EAAE,SAAS,CAAC,EACxE,MAAM,EAAE;IACR,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,YAAY,CAAC;IACvB,eAAe,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CAC9B,GAAG,UAAU,CAAC,OAAO,CAAC,CAuPtB"}
1
+ {"version":3,"file":"createRouter.d.ts","sourceRoot":"","sources":["../../packages/core/createRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIpD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAWhD,wBAAgB,YAAY,CAC1B,OAAO,SAAS,MAAM,CAAC,MAAM,GAAG,UAAU,GAAG,eAAe,EAAE,SAAS,CAAC,EACxE,MAAM,EAAE;IACR,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,YAAY,CAAC;IACvB,eAAe,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CAC9B,GAAG,UAAU,CAAC,OAAO,CAAC,CAgRtB"}
@@ -1,12 +1,10 @@
1
1
  import { TypeRouteRaw } from './types/TypeRouteRaw';
2
2
  export declare function createRoutes<TConfig extends {
3
3
  [Key in keyof TConfig | 'notFound' | 'internalError']: TypeRouteRaw;
4
- }>(config: TConfig): {
5
- [Key in keyof TConfig]: TConfig[Key] & {
6
- name: Key;
7
- pageId?: string;
8
- component?: any;
9
- otherExports?: Record<string, any>;
10
- };
11
- };
4
+ }>(config: TConfig): { [Key in keyof TConfig]: TConfig[Key] & {
5
+ name: Key;
6
+ pageId?: string;
7
+ component?: any;
8
+ otherExports?: Record<string, any>;
9
+ }; };
12
10
  //# sourceMappingURL=createRoutes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createRoutes.d.ts","sourceRoot":"","sources":["../../packages/core/createRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,wBAAgB,YAAY,CAC1B,OAAO,SAAS;KAAG,GAAG,IAAI,MAAM,OAAO,GAAG,UAAU,GAAG,eAAe,GAAG,YAAY;CAAE,EAEvF,MAAM,EAAE,OAAO,GACd;KACA,GAAG,IAAI,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG;QACrC,IAAI,EAAE,GAAG,CAAC;QACV,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,GAAG,CAAC;QAChB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACpC;CACF,CAEA"}
1
+ {"version":3,"file":"createRoutes.d.ts","sourceRoot":"","sources":["../../packages/core/createRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,wBAAgB,YAAY,CAC1B,OAAO,SAAS;KAAG,GAAG,IAAI,MAAM,OAAO,GAAG,UAAU,GAAG,eAAe,GAAG,YAAY;CAAE,EACvF,MAAM,EAAE,OAAO,GAKE,GACd,GAAG,IAAI,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG;IACrC,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACpC,GACF,CACF"}
@@ -6,5 +6,6 @@ export type TypeCurrentRoute<TRoute extends TypeRoute> = {
6
6
  query: Partial<Record<keyof TRoute['query'], string>>;
7
7
  params: Record<keyof TRoute['params'], string>;
8
8
  pageId: TRoute['pageId'];
9
+ isActive: boolean;
9
10
  };
10
11
  //# sourceMappingURL=TypeCurrentRoute.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TypeCurrentRoute.d.ts","sourceRoot":"","sources":["../../../packages/core/types/TypeCurrentRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,SAAS,IAAI;IACvD,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACtD,MAAM,EAAE,MAAM,CAAC,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;CAC1B,CAAC"}
1
+ {"version":3,"file":"TypeCurrentRoute.d.ts","sourceRoot":"","sources":["../../../packages/core/types/TypeCurrentRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,SAAS,IAAI;IACvD,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACtD,MAAM,EAAE,MAAM,CAAC,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC"}
@@ -5,15 +5,19 @@ import { TypeRoute } from './TypeRoute';
5
5
  export type TypeRouter<TRoutes extends Record<string | 'notFound' | 'internalError', TypeRoute>> = {
6
6
  routes: TRoutes;
7
7
  adapters: TypeAdapters;
8
- currentRoute: TypeCurrentRoute<TRoutes[keyof TRoutes]>;
8
+ currentRoute: {
9
+ [TRouteName in keyof TRoutes | 'notFound' | 'internalError']: TypeCurrentRoute<TRoutes[TRouteName]> | undefined;
10
+ };
9
11
  isRedirecting: boolean;
10
- redirect<TRouteName extends keyof TRoutes>(config: TypeRedirectParams<TRoutes, TRouteName>): Promise<void>;
12
+ redirect<TRouteName extends keyof TRoutes>(config: TypeRedirectParams<TRoutes, TRouteName>): Promise<string>;
11
13
  restoreFromURL(params: {
12
14
  pathname: string;
13
15
  replace?: boolean;
14
- }): Promise<void>;
16
+ }): Promise<string>;
15
17
  restoreFromServer(obj: {
16
- currentRoute: TypeCurrentRoute<TRoutes[keyof TRoutes]>;
18
+ currentRoute: {
19
+ [TRouteName in keyof TRoutes]: TypeCurrentRoute<TRoutes[TRouteName]> | undefined;
20
+ };
17
21
  }): Promise<void>;
18
22
  lifecycleParams?: Array<any>;
19
23
  destroy(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"TypeRouter.d.ts","sourceRoot":"","sources":["../../../packages/core/types/TypeRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,UAAU,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,GAAG,UAAU,GAAG,eAAe,EAAE,SAAS,CAAC,IAAI;IACjG,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,YAAY,CAAC;IACvB,YAAY,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC;IACvD,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,UAAU,SAAS,MAAM,OAAO,EACvC,MAAM,EAAE,kBAAkB,CAAC,OAAO,EAAE,UAAU,CAAC,GAC9C,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,cAAc,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/E,iBAAiB,CAAC,GAAG,EAAE;QAAE,YAAY,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClG,eAAe,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC"}
1
+ {"version":3,"file":"TypeRouter.d.ts","sourceRoot":"","sources":["../../../packages/core/types/TypeRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,UAAU,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,GAAG,UAAU,GAAG,eAAe,EAAE,SAAS,CAAC,IAAI;IACjG,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,YAAY,CAAC;IACvB,YAAY,EAAE;SACX,UAAU,IAAI,MAAM,OAAO,GAAG,UAAU,GAAG,eAAe,GACvD,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GACrC,SAAS;KACd,CAAC;IACF,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,UAAU,SAAS,MAAM,OAAO,EACvC,MAAM,EAAE,kBAAkB,CAAC,OAAO,EAAE,UAAU,CAAC,GAC9C,OAAO,CAAC,MAAM,CAAC,CAAC;IACnB,cAAc,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjF,iBAAiB,CAAC,GAAG,EAAE;QACrB,YAAY,EAAE;aACX,UAAU,IAAI,MAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,SAAS;SACjF,CAAC;KACH,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClB,eAAe,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC"}
@@ -1,6 +1,4 @@
1
1
  export declare const constants: {
2
- dynamicSeparator: string;
3
- pathPartSeparator: string;
4
2
  isClient: boolean;
5
3
  };
6
4
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;CAIrB,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;CAErB,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import { TypeRoute } from '../types/TypeRoute';
2
2
  import { TypeValidator } from '../types/TypeValidator';
3
3
  export declare function isDynamic(param: string): boolean;
4
- export declare function clearDynamic(param: string): string;
5
4
  export declare function isDynamicRoute<TRoute extends TypeRoute>(route: TRoute): route is TRoute & {
6
5
  params: Record<keyof TRoute, TypeValidator>;
7
6
  };
7
+ export declare function clearDynamic(param: string): string;
8
8
  //# sourceMappingURL=dynamic.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dynamic.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/dynamic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGvD,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,cAAc,CAAC,MAAM,SAAS,SAAS,EACrD,KAAK,EAAE,MAAM,GACZ,KAAK,IAAI,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC,MAAM,MAAM,EAAE,aAAa,CAAC,CAAA;CAAE,CAEnE"}
1
+ {"version":3,"file":"dynamic.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/dynamic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED,wBAAgB,cAAc,CAAC,MAAM,SAAS,SAAS,EACrD,KAAK,EAAE,MAAM,GACZ,KAAK,IAAI,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC,MAAM,MAAM,EAAE,aAAa,CAAC,CAAA;CAAE,CAEnE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD"}
@@ -1 +1 @@
1
- {"version":3,"file":"findRouteByPathname.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/findRouteByPathname.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAW/C,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,EAC7E,QAAQ,EACR,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;CACjB,GAAG,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,SAAS,CAuDrC"}
1
+ {"version":3,"file":"findRouteByPathname.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/findRouteByPathname.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAO/C,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,EAC7E,QAAQ,EACR,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;CACjB,GAAG,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,SAAS,CAkDrC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getDynamicValues.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/getDynamicValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,wBAAgB,gBAAgB,CAAC,MAAM,SAAS,SAAS,EAAE,MAAM,EAAE;IACjE,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,MAAM,CAAC,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAqBzC"}
1
+ {"version":3,"file":"getDynamicValues.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/getDynamicValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C,wBAAgB,gBAAgB,CAAC,MAAM,SAAS,SAAS,EAAE,MAAM,EAAE;IACjE,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,MAAM,CAAC,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAqBzC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getQueryValues.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/getQueryValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,wBAAgB,cAAc,CAAC,MAAM,SAAS,SAAS,EAAE,MAAM,EAAE;IAC/D,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAkBjD"}
1
+ {"version":3,"file":"getQueryValues.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/getQueryValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,wBAAgB,cAAc,CAAC,MAAM,SAAS,SAAS,EAAE,MAAM,EAAE;IAC/D,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAoBjD"}
@@ -1 +1 @@
1
- {"version":3,"file":"replaceDynamicValues.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/replaceDynamicValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAM/C,wBAAgB,oBAAoB,CAAC,UAAU,SAAS,SAAS,GAAG,gBAAgB,CAAC,SAAS,CAAC,EAAE,EAC/F,KAAK,EACL,MAAkB,GACnB,EAAE;IACD,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;CACrD,GAAG,MAAM,CAcT"}
1
+ {"version":3,"file":"replaceDynamicValues.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/replaceDynamicValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAK/C,wBAAgB,oBAAoB,CAAC,UAAU,SAAS,SAAS,GAAG,gBAAgB,CAAC,SAAS,CAAC,EAAE,EAC/F,KAAK,EACL,MAAkB,GACnB,EAAE;IACD,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;CACrD,GAAG,MAAM,CAcT"}
@@ -1 +1 @@
1
- {"version":3,"file":"routerSetLoadedComponent.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/routerSetLoadedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,eAAe,CAAC,GAAG,CAAC,EAC3B,MAAM,EAAE;IACN,mBAAmB,CAAC,EAAE,GAAG,CAAC;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACnC,QA8BF"}
1
+ {"version":3,"file":"routerSetLoadedComponent.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/routerSetLoadedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,eAAe,CAAC,GAAG,CAAC,EAC3B,MAAM,EAAE;IACN,mBAAmB,CAAC,EAAE,GAAG,CAAC;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACnC,QAoCF"}
package/index.cjs CHANGED
@@ -31,24 +31,22 @@ module.exports = __toCommonJS(core_exports);
31
31
 
32
32
  // packages/core/utils/constants.ts
33
33
  var constants = {
34
- dynamicSeparator: ":",
35
- pathPartSeparator: "/",
36
34
  isClient: typeof window !== "undefined"
37
35
  };
38
36
 
39
37
  // packages/core/utils/dynamic.ts
40
38
  function isDynamic(param) {
41
- return param[0] === constants.dynamicSeparator;
39
+ return param[0] === ":";
42
40
  }
43
41
  function clearDynamic(param) {
44
- return param.replace(new RegExp(`^${constants.dynamicSeparator}`), "");
42
+ return param.replace(/^:/, "");
45
43
  }
46
44
 
47
45
  // packages/core/utils/getDynamicValues.ts
48
46
  function getDynamicValues(params) {
49
47
  const { route, pathname } = params;
50
- const pathnameArray = pathname.replace(/\?.+$/, "").split(constants.pathPartSeparator).filter(Boolean).map((str) => decodeURIComponent(str));
51
- const routePathnameArray = route.path.split(constants.pathPartSeparator).filter(Boolean);
48
+ const pathnameArray = pathname.replace(/\?.+$/, "").split("/").filter(Boolean).map((str) => decodeURIComponent(str));
49
+ const routePathnameArray = route.path.split("/").filter(Boolean);
52
50
  const dynamicParams = {};
53
51
  for (let i = 0; i < routePathnameArray.length; i++) {
54
52
  const paramName = routePathnameArray[i];
@@ -59,20 +57,20 @@ function getDynamicValues(params) {
59
57
 
60
58
  // packages/core/utils/findRouteByPathname.ts
61
59
  function completeStaticMatch(pathname, path) {
62
- return !path.includes(constants.dynamicSeparator) && (pathname === path || pathname === `${path}${constants.pathPartSeparator}`);
60
+ return !path.includes(":") && (pathname === path || pathname === `${path}/`);
63
61
  }
64
62
  function findRouteByPathname({
65
63
  pathname,
66
64
  routes
67
65
  }) {
68
66
  let dynamicRouteMatch;
69
- const pathnameArray = pathname.replace(/\?.+$/, "").split(constants.pathPartSeparator).filter(Boolean);
67
+ const pathnameArray = pathname.replace(/\?.+$/, "").split("/").filter(Boolean);
70
68
  for (const routeName in routes) {
71
69
  if (!Object.hasOwn(routes, routeName)) continue;
72
70
  const route = routes[routeName];
73
71
  if (completeStaticMatch(pathname, route.path)) return route;
74
72
  if (dynamicRouteMatch) continue;
75
- const routePathnameArray = route.path.split(constants.pathPartSeparator).filter(Boolean);
73
+ const routePathnameArray = route.path.split("/").filter(Boolean);
76
74
  if (routePathnameArray.length !== pathnameArray.length) continue;
77
75
  const someParamInvalid = routePathnameArray.some((paramName, i) => {
78
76
  const paramFromUrl = pathnameArray[i];
@@ -113,8 +111,9 @@ var queryString = {
113
111
  // packages/core/utils/getQueryValues.ts
114
112
  function getQueryValues(params) {
115
113
  const { route, pathname } = params;
114
+ if (!route.query) return {};
116
115
  const qs = queryString.extract(pathname);
117
- if (!qs || !route.query) return {};
116
+ if (!qs) return {};
118
117
  const query = queryString.parse(qs);
119
118
  getTypedEntries(query).forEach(([key, value]) => {
120
119
  const validator = route.query[key];
@@ -166,7 +165,7 @@ var RedirectError = class extends Error {
166
165
  };
167
166
 
168
167
  // packages/core/utils/replaceDynamicValues.ts
169
- var re = new RegExp(`[^${constants.pathPartSeparator}]+`, "g");
168
+ var re = new RegExp(`[^/]+`, "g");
170
169
  function replaceDynamicValues({
171
170
  route,
172
171
  params = {}
@@ -206,8 +205,11 @@ function createRouter(config) {
206
205
  router.adapters.batch(() => {
207
206
  Object.assign(router.currentRoute, obj.currentRoute);
208
207
  });
208
+ const activeRoute = Object.values(
209
+ router.currentRoute
210
+ ).find((currentRoute) => currentRoute?.isActive);
209
211
  const preloadedRouteName = Object.keys(router.routes).find(
210
- (routeName) => router.currentRoute.name === routeName
212
+ (routeName) => activeRoute?.name === routeName
211
213
  );
212
214
  return loadComponentToConfig({ route: router.routes[preloadedRouteName] });
213
215
  };
@@ -221,14 +223,14 @@ function createRouter(config) {
221
223
  let currentUrl;
222
224
  let currentSearch;
223
225
  let currentQuery;
224
- if (router.currentRoute?.name) {
225
- currentRoute = router.routes[router.currentRoute.name];
226
- currentPathname = replaceDynamicValues({
227
- route: currentRoute,
228
- params: router.currentRoute.params
229
- });
230
- currentQuery = router.currentRoute.query;
231
- currentSearch = queryString.stringify(router.currentRoute.query);
226
+ const activeRoute = Object.values(
227
+ router.currentRoute
228
+ ).find((currentRoute2) => currentRoute2?.isActive);
229
+ if (activeRoute) {
230
+ currentRoute = router.routes[activeRoute.name];
231
+ currentPathname = replaceDynamicValues({ route: currentRoute, params: activeRoute.params });
232
+ currentQuery = activeRoute.query;
233
+ currentSearch = queryString.stringify(activeRoute.query);
232
234
  currentUrl = `${currentPathname}${currentSearch ? `?${currentSearch}` : ""}`;
233
235
  }
234
236
  const nextRoute = router.routes[routeName];
@@ -250,12 +252,12 @@ function createRouter(config) {
250
252
  nextUrl = `${nextPathname}?${nextSearch}`;
251
253
  }
252
254
  }
253
- if (currentUrl === nextUrl) return Promise.resolve();
255
+ if (currentUrl === nextUrl) return nextUrl;
254
256
  if (currentPathname === nextPathname) {
255
257
  if (currentSearch !== nextSearch) {
256
258
  router.adapters.batch(() => {
257
- router.adapters.replaceObject(router.currentRoute, {
258
- ...router.currentRoute,
259
+ router.adapters.replaceObject(router.currentRoute[routeName], {
260
+ ...router.currentRoute[routeName],
259
261
  query: nextQuery || {}
260
262
  });
261
263
  });
@@ -263,7 +265,7 @@ function createRouter(config) {
263
265
  window.history[replace ? "replaceState" : "pushState"](null, "", nextUrl);
264
266
  }
265
267
  }
266
- return Promise.resolve();
268
+ return nextUrl;
267
269
  }
268
270
  router.adapters.batch(() => {
269
271
  router.isRedirecting = true;
@@ -309,7 +311,7 @@ function createRouter(config) {
309
311
  await loadComponentToConfig({ route: router.routes[nextRoute.name] });
310
312
  } catch (error) {
311
313
  if (error instanceof PreventError) {
312
- return Promise.resolve();
314
+ return currentUrl;
313
315
  }
314
316
  if (error instanceof RedirectError) {
315
317
  throw error;
@@ -317,33 +319,48 @@ function createRouter(config) {
317
319
  console.error(error);
318
320
  await loadComponentToConfig({ route: router.routes.internalError });
319
321
  router.adapters.batch(() => {
320
- router.adapters.replaceObject(router.currentRoute, {
322
+ const newObj = {
321
323
  name: router.routes.internalError.name,
322
324
  path: router.routes.internalError.path,
323
325
  props: router.routes[router.routes.internalError.name].props,
324
326
  query: router.adapters.makeObservable({}),
325
327
  params: router.adapters.makeObservable({}),
326
- pageId: router.routes[router.routes.internalError.name].pageId
328
+ pageId: router.routes[router.routes.internalError.name].pageId,
329
+ isActive: true
330
+ };
331
+ if (!router.currentRoute.internalError) router.currentRoute.internalError = newObj;
332
+ else router.adapters.replaceObject(router.currentRoute.internalError, newObj);
333
+ Object.values(router.currentRoute).forEach((r) => {
334
+ if (r && r.name !== "internalError") r.isActive = false;
327
335
  });
328
336
  router.isRedirecting = false;
329
337
  });
330
- return Promise.resolve();
338
+ return nextUrl;
331
339
  }
332
340
  router.adapters.batch(() => {
333
- router.adapters.replaceObject(router.currentRoute, {
341
+ const newObj = {
334
342
  name: nextRoute.name,
335
343
  path: nextRoute.path,
336
344
  props: router.routes[nextRoute.name].props,
337
345
  query: getQueryValues({ route: nextRoute, pathname: nextUrl }),
338
346
  params: getDynamicValues({ route: nextRoute, pathname: nextUrl }),
339
- pageId: router.routes[nextRoute.name].pageId
347
+ pageId: router.routes[nextRoute.name].pageId,
348
+ isActive: true
349
+ };
350
+ if (!router.currentRoute[routeName]) {
351
+ router.currentRoute[routeName] = newObj;
352
+ } else {
353
+ router.adapters.replaceObject(router.currentRoute[routeName], newObj);
354
+ }
355
+ Object.values(router.currentRoute).forEach((r) => {
356
+ if (r && r.name !== routeName) r.isActive = false;
340
357
  });
341
358
  if (constants.isClient) {
342
359
  window.history[replace ? "replaceState" : "pushState"](null, "", nextUrl);
343
360
  }
344
361
  router.isRedirecting = false;
345
362
  });
346
- return Promise.resolve();
363
+ return nextUrl;
347
364
  };
348
365
  function popHandler() {
349
366
  const currentUrl = `${location.pathname}${location.search}`;
@@ -360,23 +377,21 @@ function createRouter(config) {
360
377
  return router;
361
378
  }
362
379
 
363
- // packages/core/utils/addNames.ts
364
- function addNames(obj) {
365
- Object.entries(obj).forEach(([key, value]) => {
366
- value.name = key;
367
- });
368
- return obj;
369
- }
370
-
371
380
  // packages/core/createRoutes.ts
372
381
  function createRoutes(config) {
373
- return addNames(config);
382
+ Object.entries(config).forEach(([key, value]) => {
383
+ value.name = key;
384
+ });
385
+ return config;
374
386
  }
375
387
 
376
388
  // packages/core/utils/routerSetLoadedComponent.ts
377
389
  function routerSetLoadedComponent(props, config) {
378
- const currentRouteName = props.router.currentRoute.name;
379
- const currentRoutePage = props.router.currentRoute.pageId;
390
+ const activeRoute = Object.values(props.router.currentRoute).find(
391
+ (currentRoute) => currentRoute?.isActive
392
+ );
393
+ const currentRouteName = activeRoute?.name;
394
+ const currentRoutePage = activeRoute?.pageId;
380
395
  const componentConfig = props.router.routes[currentRouteName];
381
396
  let preventRedirect = false;
382
397
  if (props.router.isRedirecting) preventRedirect = true;
package/index.mjs CHANGED
@@ -1,23 +1,21 @@
1
1
  // packages/core/utils/constants.ts
2
2
  var constants = {
3
- dynamicSeparator: ":",
4
- pathPartSeparator: "/",
5
3
  isClient: typeof window !== "undefined"
6
4
  };
7
5
 
8
6
  // packages/core/utils/dynamic.ts
9
7
  function isDynamic(param) {
10
- return param[0] === constants.dynamicSeparator;
8
+ return param[0] === ":";
11
9
  }
12
10
  function clearDynamic(param) {
13
- return param.replace(new RegExp(`^${constants.dynamicSeparator}`), "");
11
+ return param.replace(/^:/, "");
14
12
  }
15
13
 
16
14
  // packages/core/utils/getDynamicValues.ts
17
15
  function getDynamicValues(params) {
18
16
  const { route, pathname } = params;
19
- const pathnameArray = pathname.replace(/\?.+$/, "").split(constants.pathPartSeparator).filter(Boolean).map((str) => decodeURIComponent(str));
20
- const routePathnameArray = route.path.split(constants.pathPartSeparator).filter(Boolean);
17
+ const pathnameArray = pathname.replace(/\?.+$/, "").split("/").filter(Boolean).map((str) => decodeURIComponent(str));
18
+ const routePathnameArray = route.path.split("/").filter(Boolean);
21
19
  const dynamicParams = {};
22
20
  for (let i = 0; i < routePathnameArray.length; i++) {
23
21
  const paramName = routePathnameArray[i];
@@ -28,20 +26,20 @@ function getDynamicValues(params) {
28
26
 
29
27
  // packages/core/utils/findRouteByPathname.ts
30
28
  function completeStaticMatch(pathname, path) {
31
- return !path.includes(constants.dynamicSeparator) && (pathname === path || pathname === `${path}${constants.pathPartSeparator}`);
29
+ return !path.includes(":") && (pathname === path || pathname === `${path}/`);
32
30
  }
33
31
  function findRouteByPathname({
34
32
  pathname,
35
33
  routes
36
34
  }) {
37
35
  let dynamicRouteMatch;
38
- const pathnameArray = pathname.replace(/\?.+$/, "").split(constants.pathPartSeparator).filter(Boolean);
36
+ const pathnameArray = pathname.replace(/\?.+$/, "").split("/").filter(Boolean);
39
37
  for (const routeName in routes) {
40
38
  if (!Object.hasOwn(routes, routeName)) continue;
41
39
  const route = routes[routeName];
42
40
  if (completeStaticMatch(pathname, route.path)) return route;
43
41
  if (dynamicRouteMatch) continue;
44
- const routePathnameArray = route.path.split(constants.pathPartSeparator).filter(Boolean);
42
+ const routePathnameArray = route.path.split("/").filter(Boolean);
45
43
  if (routePathnameArray.length !== pathnameArray.length) continue;
46
44
  const someParamInvalid = routePathnameArray.some((paramName, i) => {
47
45
  const paramFromUrl = pathnameArray[i];
@@ -82,8 +80,9 @@ var queryString = {
82
80
  // packages/core/utils/getQueryValues.ts
83
81
  function getQueryValues(params) {
84
82
  const { route, pathname } = params;
83
+ if (!route.query) return {};
85
84
  const qs = queryString.extract(pathname);
86
- if (!qs || !route.query) return {};
85
+ if (!qs) return {};
87
86
  const query = queryString.parse(qs);
88
87
  getTypedEntries(query).forEach(([key, value]) => {
89
88
  const validator = route.query[key];
@@ -135,7 +134,7 @@ var RedirectError = class extends Error {
135
134
  };
136
135
 
137
136
  // packages/core/utils/replaceDynamicValues.ts
138
- var re = new RegExp(`[^${constants.pathPartSeparator}]+`, "g");
137
+ var re = new RegExp(`[^/]+`, "g");
139
138
  function replaceDynamicValues({
140
139
  route,
141
140
  params = {}
@@ -175,8 +174,11 @@ function createRouter(config) {
175
174
  router.adapters.batch(() => {
176
175
  Object.assign(router.currentRoute, obj.currentRoute);
177
176
  });
177
+ const activeRoute = Object.values(
178
+ router.currentRoute
179
+ ).find((currentRoute) => currentRoute?.isActive);
178
180
  const preloadedRouteName = Object.keys(router.routes).find(
179
- (routeName) => router.currentRoute.name === routeName
181
+ (routeName) => activeRoute?.name === routeName
180
182
  );
181
183
  return loadComponentToConfig({ route: router.routes[preloadedRouteName] });
182
184
  };
@@ -190,14 +192,14 @@ function createRouter(config) {
190
192
  let currentUrl;
191
193
  let currentSearch;
192
194
  let currentQuery;
193
- if (router.currentRoute?.name) {
194
- currentRoute = router.routes[router.currentRoute.name];
195
- currentPathname = replaceDynamicValues({
196
- route: currentRoute,
197
- params: router.currentRoute.params
198
- });
199
- currentQuery = router.currentRoute.query;
200
- currentSearch = queryString.stringify(router.currentRoute.query);
195
+ const activeRoute = Object.values(
196
+ router.currentRoute
197
+ ).find((currentRoute2) => currentRoute2?.isActive);
198
+ if (activeRoute) {
199
+ currentRoute = router.routes[activeRoute.name];
200
+ currentPathname = replaceDynamicValues({ route: currentRoute, params: activeRoute.params });
201
+ currentQuery = activeRoute.query;
202
+ currentSearch = queryString.stringify(activeRoute.query);
201
203
  currentUrl = `${currentPathname}${currentSearch ? `?${currentSearch}` : ""}`;
202
204
  }
203
205
  const nextRoute = router.routes[routeName];
@@ -219,12 +221,12 @@ function createRouter(config) {
219
221
  nextUrl = `${nextPathname}?${nextSearch}`;
220
222
  }
221
223
  }
222
- if (currentUrl === nextUrl) return Promise.resolve();
224
+ if (currentUrl === nextUrl) return nextUrl;
223
225
  if (currentPathname === nextPathname) {
224
226
  if (currentSearch !== nextSearch) {
225
227
  router.adapters.batch(() => {
226
- router.adapters.replaceObject(router.currentRoute, {
227
- ...router.currentRoute,
228
+ router.adapters.replaceObject(router.currentRoute[routeName], {
229
+ ...router.currentRoute[routeName],
228
230
  query: nextQuery || {}
229
231
  });
230
232
  });
@@ -232,7 +234,7 @@ function createRouter(config) {
232
234
  window.history[replace ? "replaceState" : "pushState"](null, "", nextUrl);
233
235
  }
234
236
  }
235
- return Promise.resolve();
237
+ return nextUrl;
236
238
  }
237
239
  router.adapters.batch(() => {
238
240
  router.isRedirecting = true;
@@ -278,7 +280,7 @@ function createRouter(config) {
278
280
  await loadComponentToConfig({ route: router.routes[nextRoute.name] });
279
281
  } catch (error) {
280
282
  if (error instanceof PreventError) {
281
- return Promise.resolve();
283
+ return currentUrl;
282
284
  }
283
285
  if (error instanceof RedirectError) {
284
286
  throw error;
@@ -286,33 +288,48 @@ function createRouter(config) {
286
288
  console.error(error);
287
289
  await loadComponentToConfig({ route: router.routes.internalError });
288
290
  router.adapters.batch(() => {
289
- router.adapters.replaceObject(router.currentRoute, {
291
+ const newObj = {
290
292
  name: router.routes.internalError.name,
291
293
  path: router.routes.internalError.path,
292
294
  props: router.routes[router.routes.internalError.name].props,
293
295
  query: router.adapters.makeObservable({}),
294
296
  params: router.adapters.makeObservable({}),
295
- pageId: router.routes[router.routes.internalError.name].pageId
297
+ pageId: router.routes[router.routes.internalError.name].pageId,
298
+ isActive: true
299
+ };
300
+ if (!router.currentRoute.internalError) router.currentRoute.internalError = newObj;
301
+ else router.adapters.replaceObject(router.currentRoute.internalError, newObj);
302
+ Object.values(router.currentRoute).forEach((r) => {
303
+ if (r && r.name !== "internalError") r.isActive = false;
296
304
  });
297
305
  router.isRedirecting = false;
298
306
  });
299
- return Promise.resolve();
307
+ return nextUrl;
300
308
  }
301
309
  router.adapters.batch(() => {
302
- router.adapters.replaceObject(router.currentRoute, {
310
+ const newObj = {
303
311
  name: nextRoute.name,
304
312
  path: nextRoute.path,
305
313
  props: router.routes[nextRoute.name].props,
306
314
  query: getQueryValues({ route: nextRoute, pathname: nextUrl }),
307
315
  params: getDynamicValues({ route: nextRoute, pathname: nextUrl }),
308
- pageId: router.routes[nextRoute.name].pageId
316
+ pageId: router.routes[nextRoute.name].pageId,
317
+ isActive: true
318
+ };
319
+ if (!router.currentRoute[routeName]) {
320
+ router.currentRoute[routeName] = newObj;
321
+ } else {
322
+ router.adapters.replaceObject(router.currentRoute[routeName], newObj);
323
+ }
324
+ Object.values(router.currentRoute).forEach((r) => {
325
+ if (r && r.name !== routeName) r.isActive = false;
309
326
  });
310
327
  if (constants.isClient) {
311
328
  window.history[replace ? "replaceState" : "pushState"](null, "", nextUrl);
312
329
  }
313
330
  router.isRedirecting = false;
314
331
  });
315
- return Promise.resolve();
332
+ return nextUrl;
316
333
  };
317
334
  function popHandler() {
318
335
  const currentUrl = `${location.pathname}${location.search}`;
@@ -329,23 +346,21 @@ function createRouter(config) {
329
346
  return router;
330
347
  }
331
348
 
332
- // packages/core/utils/addNames.ts
333
- function addNames(obj) {
334
- Object.entries(obj).forEach(([key, value]) => {
335
- value.name = key;
336
- });
337
- return obj;
338
- }
339
-
340
349
  // packages/core/createRoutes.ts
341
350
  function createRoutes(config) {
342
- return addNames(config);
351
+ Object.entries(config).forEach(([key, value]) => {
352
+ value.name = key;
353
+ });
354
+ return config;
343
355
  }
344
356
 
345
357
  // packages/core/utils/routerSetLoadedComponent.ts
346
358
  function routerSetLoadedComponent(props, config) {
347
- const currentRouteName = props.router.currentRoute.name;
348
- const currentRoutePage = props.router.currentRoute.pageId;
359
+ const activeRoute = Object.values(props.router.currentRoute).find(
360
+ (currentRoute) => currentRoute?.isActive
361
+ );
362
+ const currentRouteName = activeRoute?.name;
363
+ const currentRoutePage = activeRoute?.pageId;
349
364
  const componentConfig = props.router.routes[currentRouteName];
350
365
  let preventRedirect = false;
351
366
  if (props.router.isRedirecting) preventRedirect = true;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "reactive-route",
3
3
  "author": "Dmitry Kazakov",
4
4
  "license": "MIT",
5
- "version": "0.0.1-alpha.33",
5
+ "version": "0.0.1-alpha.35",
6
6
  "description": "Reactive Router for different frameworks",
7
7
  "repository": {
8
8
  "type": "git",
@@ -1,3 +1,3 @@
1
1
  import { TypePropsRouter, TypeRoute } from 'reactive-route';
2
- export declare function Router<TRoutes extends Record<string, TypeRoute>>(props: TypePropsRouter<TRoutes>): any;
2
+ export declare function Router<TRoutes extends Record<string, TypeRoute>>(props: TypePropsRouter<TRoutes>): import("react/jsx-runtime").JSX.Element;
3
3
  //# sourceMappingURL=Router.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../packages/preact/Router.tsx"],"names":[],"mappings":"AACA,OAAO,EAA4B,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA6CtF,wBAAgB,MAAM,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,GAK1D,GAAG,CACzC"}
1
+ {"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../packages/preact/Router.tsx"],"names":[],"mappings":"AACA,OAAO,EAA4B,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA0CtF,wBAAgB,MAAM,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,2CAIhG"}
package/preact/index.cjs CHANGED
@@ -52,14 +52,10 @@ function RouterInner(props) {
52
52
  };
53
53
  }, []);
54
54
  if (!config.loadedComponentName) return null;
55
- const LoadedComponent = props.router.routes[config.loadedComponentName]?.component || null;
56
- if (LoadedComponent)
57
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadedComponent, { ...config.currentProps, router: props.router });
58
- return null;
55
+ const LoadedComponent = props.router.routes[config.loadedComponentName].component;
56
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadedComponent, { ...config.currentProps, router: props.router });
59
57
  }
60
58
  function Router(props) {
61
- const [Component] = (0, import_hooks.useState)(
62
- () => props.router.adapters.observer ? props.router.adapters.observer(RouterInner) : RouterInner
63
- );
59
+ const [Component] = (0, import_hooks.useState)(() => props.router.adapters.observer(RouterInner));
64
60
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...props });
65
61
  }
package/preact/index.mjs CHANGED
@@ -26,15 +26,11 @@ function RouterInner(props) {
26
26
  };
27
27
  }, []);
28
28
  if (!config.loadedComponentName) return null;
29
- const LoadedComponent = props.router.routes[config.loadedComponentName]?.component || null;
30
- if (LoadedComponent)
31
- return /* @__PURE__ */ jsx(LoadedComponent, { ...config.currentProps, router: props.router });
32
- return null;
29
+ const LoadedComponent = props.router.routes[config.loadedComponentName].component;
30
+ return /* @__PURE__ */ jsx(LoadedComponent, { ...config.currentProps, router: props.router });
33
31
  }
34
32
  function Router(props) {
35
- const [Component] = useState(
36
- () => props.router.adapters.observer ? props.router.adapters.observer(RouterInner) : RouterInner
37
- );
33
+ const [Component] = useState(() => props.router.adapters.observer(RouterInner));
38
34
  return /* @__PURE__ */ jsx(Component, { ...props });
39
35
  }
40
36
  export {
package/react/Router.d.ts CHANGED
@@ -1,5 +1,3 @@
1
1
  import { TypePropsRouter, TypeRoute } from 'reactive-route';
2
- declare function RouterWrapper<TRoutes extends Record<string, TypeRoute>>(props: TypePropsRouter<TRoutes>): any;
3
- export declare const Router: typeof RouterWrapper;
4
- export {};
2
+ export declare function Router<TRoutes extends Record<string, TypeRoute>>(props: TypePropsRouter<TRoutes>): import("react/jsx-runtime").JSX.Element;
5
3
  //# sourceMappingURL=Router.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../packages/react/Router.tsx"],"names":[],"mappings":"AACA,OAAO,EAA4B,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA6CtF,iBAAS,aAAa,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,GAK1D,GAAG,CACzC;AAED,eAAO,MAAM,MAAM,EAA0B,OAAO,aAAa,CAAC"}
1
+ {"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../packages/react/Router.tsx"],"names":[],"mappings":"AACA,OAAO,EAA4B,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA0CtF,wBAAgB,MAAM,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,2CAIhG"}
package/react/index.cjs CHANGED
@@ -52,13 +52,10 @@ function RouterInner(props) {
52
52
  };
53
53
  }, []);
54
54
  if (!config.loadedComponentName) return null;
55
- const LoadedComponent = props.router.routes[config.loadedComponentName]?.component || null;
56
- if (LoadedComponent)
57
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadedComponent, { ...config.currentProps, router: props.router });
58
- return null;
55
+ const LoadedComponent = props.router.routes[config.loadedComponentName].component;
56
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadedComponent, { ...config.currentProps, router: props.router });
59
57
  }
60
- function RouterWrapper(props) {
61
- const Component = props.router.adapters.observer ? props.router.adapters.observer(RouterInner) : RouterInner;
58
+ function Router(props) {
59
+ const [Component] = (0, import_react.useState)(() => props.router.adapters.observer(RouterInner));
62
60
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...props });
63
61
  }
64
- var Router = (0, import_react.memo)(RouterWrapper);
package/react/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // packages/react/Router.tsx
2
- import { memo, useEffect, useRef, useState } from "react";
2
+ import { useEffect, useRef, useState } from "react";
3
3
  import { routerSetLoadedComponent } from "reactive-route";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  function RouterInner(props) {
@@ -26,16 +26,13 @@ function RouterInner(props) {
26
26
  };
27
27
  }, []);
28
28
  if (!config.loadedComponentName) return null;
29
- const LoadedComponent = props.router.routes[config.loadedComponentName]?.component || null;
30
- if (LoadedComponent)
31
- return /* @__PURE__ */ jsx(LoadedComponent, { ...config.currentProps, router: props.router });
32
- return null;
29
+ const LoadedComponent = props.router.routes[config.loadedComponentName].component;
30
+ return /* @__PURE__ */ jsx(LoadedComponent, { ...config.currentProps, router: props.router });
33
31
  }
34
- function RouterWrapper(props) {
35
- const Component = props.router.adapters.observer ? props.router.adapters.observer(RouterInner) : RouterInner;
32
+ function Router(props) {
33
+ const [Component] = useState(() => props.router.adapters.observer(RouterInner));
36
34
  return /* @__PURE__ */ jsx(Component, { ...props });
37
35
  }
38
- var Router = memo(RouterWrapper);
39
36
  export {
40
37
  Router
41
38
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../packages/solid/Router.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA4B,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAItF,wBAAgB,MAAM,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,kCAsChG"}
1
+ {"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../packages/solid/Router.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA4B,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAItF,wBAAgB,MAAM,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,kCAoChG"}
package/solid/index.cjs CHANGED
@@ -55,7 +55,7 @@ function Router(props) {
55
55
  get children() {
56
56
  return (0, import_web.createComponent)(import_web3.Dynamic, (0, import_web2.mergeProps)({
57
57
  get component() {
58
- return props.router.routes[config.loadedComponentName]?.component || void 0;
58
+ return props.router.routes[config.loadedComponentName].component;
59
59
  }
60
60
  }, () => config.currentProps, {
61
61
  get router() {
package/solid/index.mjs CHANGED
@@ -29,7 +29,7 @@ function Router(props) {
29
29
  get children() {
30
30
  return _$createComponent(Dynamic, _$mergeProps({
31
31
  get component() {
32
- return props.router.routes[config.loadedComponentName]?.component || void 0;
32
+ return props.router.routes[config.loadedComponentName].component;
33
33
  }
34
34
  }, () => config.currentProps, {
35
35
  get router() {
package/vue/index.cjs CHANGED
Binary file
package/vue/index.mjs CHANGED
Binary file
@@ -1,8 +0,0 @@
1
- type TypeObjectWithNames<T> = {
2
- [Key in keyof T]: T[Key] & {
3
- name: Key;
4
- };
5
- };
6
- export declare function addNames<T extends Record<string, any>>(obj: T): TypeObjectWithNames<T>;
7
- export {};
8
- //# sourceMappingURL=addNames.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"addNames.d.ts","sourceRoot":"","sources":["../../../packages/core/utils/addNames.ts"],"names":[],"mappings":"AAAA,KAAK,mBAAmB,CAAC,CAAC,IAAI;KAAG,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG;QAAE,IAAI,EAAE,GAAG,CAAA;KAAE;CAAE,CAAC;AAE3E,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAMtF"}