@homecode/ui 4.18.29 → 4.18.31

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.
@@ -31,9 +31,12 @@ const Router = (props) => {
31
31
  }
32
32
  // @ts-ignore
33
33
  const isRouteComponent = child.type.displayName === 'Route';
34
- const { path, exact, component: Component, ...rest } = child.props;
34
+ const { path, queryParam, exact, component: Component, ...rest } = child.props;
35
35
  if (!path) {
36
- if (isRouteComponent && Component) {
36
+ const isMatched = queryParam
37
+ ? router.query[queryParam]
38
+ : isRouteComponent && Component;
39
+ if (isMatched) {
37
40
  noMatchRoute = jsx(Component, { ...rest });
38
41
  continue;
39
42
  }
@@ -20,11 +20,11 @@ const STORE = createStore('router', {
20
20
  un(cb) {
21
21
  spliceWhere(LISTENERS, cb);
22
22
  },
23
- go(path, query, params = {}) {
23
+ go(path = this.path, query = {}, params = {}) {
24
24
  if (path === this.path && !query)
25
25
  return;
26
26
  const { replace } = params;
27
- const pathStr = applyQueryParams(path ?? this.path, query, this.query);
27
+ const pathStr = applyQueryParams(path ?? this.path, query);
28
28
  const action = replace ? 'replaceState' : 'pushState';
29
29
  console.log('Router.go', query, pathStr);
30
30
  history[action]({}, '', pathStr);
@@ -15,17 +15,11 @@ function stringifyQueryParams(params) {
15
15
  .map(([key, value]) => `${key}=${value}`)
16
16
  .join('&');
17
17
  }
18
- function applyQueryParams(path, queryParams, currParams) {
18
+ function applyQueryParams(path, queryParams) {
19
19
  const clearPath = path.replace(/\?.*/, '/');
20
- if (!queryParams) {
21
- if (Object.keys(currParams).length === 0)
22
- return path;
23
- return `${clearPath}?${stringifyQueryParams(currParams)}`;
24
- }
25
- if (typeof queryParams === 'string') {
20
+ if (typeof queryParams === 'string')
26
21
  return queryParams;
27
- }
28
- const query = { ...currParams };
22
+ const query = { ...queryParams };
29
23
  Object.entries(queryParams).forEach(([key, value]) => {
30
24
  if (value === false)
31
25
  delete query[key];
@@ -5,7 +5,9 @@ export type RedirectProps = {
5
5
  to: string;
6
6
  };
7
7
  export type RouteProps = {
8
+ className?: string;
8
9
  path: string;
10
+ queryParam?: string;
9
11
  component: ComponentType;
10
12
  exact?: boolean;
11
13
  } & Partial<RedirectProps>;
@@ -1,5 +1,5 @@
1
1
  export declare function parseQueryParams(qs?: string): Record<string, string>;
2
2
  export declare function stringifyQueryParams(params: Record<string, string>): string;
3
- export declare function applyQueryParams(path: any, queryParams: any, currParams: any): any;
3
+ export declare function applyQueryParams(path: any, queryParams: Record<string, any> | string): string;
4
4
  export declare const setSSRQueryParams: (params: any) => void;
5
5
  export declare const queryParams: Record<string, string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homecode/ui",
3
- "version": "4.18.29",
3
+ "version": "4.18.31",
4
4
  "description": "React UI components library",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",