@umijs/renderer-react 4.0.0-rc.20 → 4.0.0-rc.21

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.
@@ -1,4 +1,16 @@
1
1
  import React from 'react';
2
- export declare const AppContext: React.Context<any>;
3
- export declare function useAppData(): any;
2
+ import { IClientRoute, ILoaderData, IRouteComponents, IRoutesById } from './types';
3
+ interface IAppCentextType {
4
+ routes: IRoutesById;
5
+ routeComponents: IRouteComponents;
6
+ clientRoutes: IClientRoute[];
7
+ pluginManager: any;
8
+ rootElement?: HTMLElement;
9
+ basename?: string;
10
+ clientLoaderData: ILoaderData;
11
+ preloadRoute: (to: string) => void;
12
+ }
13
+ export declare const AppContext: React.Context<IAppCentextType>;
14
+ export declare function useAppData(): IAppCentextType;
4
15
  export declare function useClientLoaderData(): any;
16
+ export {};
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { useRouteData } from './routeContext';
3
- export const AppContext = React.createContext(null);
3
+ export const AppContext = React.createContext({});
4
4
  export function useAppData() {
5
5
  return React.useContext(AppContext);
6
6
  }
package/dist/link.js CHANGED
@@ -4,5 +4,5 @@ import { useAppData } from './appContext';
4
4
  export function LinkWithPrefetch(props) {
5
5
  const appData = useAppData();
6
6
  const to = typeof props.to === 'string' ? props.to : props.to.pathname;
7
- return (React.createElement(Link, { onMouseEnter: () => props.prefetch && appData.preloadRoute(to), ...props }, props.children));
7
+ return (React.createElement(Link, { onMouseEnter: () => props.prefetch && to && appData.preloadRoute(to), ...props }, props.children));
8
8
  }
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
+ import { IRoute } from './types';
2
3
  export interface IRouteContextType {
3
- route: any;
4
+ route: IRoute;
4
5
  }
5
6
  export declare const RouteContext: React.Context<IRouteContextType | undefined>;
6
7
  export declare function useRouteData(): IRouteContextType;
package/dist/routes.d.ts CHANGED
@@ -1,27 +1,8 @@
1
1
  import React from 'react';
2
- import { IRoute, IRoutesById } from './types';
2
+ import { IClientRoute, IRoutesById } from './types';
3
3
  export declare function createClientRoutes(opts: {
4
4
  routesById: IRoutesById;
5
5
  routeComponents: Record<string, any>;
6
6
  parentId?: string;
7
7
  loadingComponent?: React.ReactNode;
8
- }): {
9
- parentId?: string | undefined;
10
- clientLoader?: (() => Promise<any>) | undefined;
11
- id: string;
12
- path: string | undefined;
13
- index: boolean | undefined;
14
- element: JSX.Element;
15
- }[];
16
- export declare function createClientRoute(opts: {
17
- route: IRoute;
18
- routeComponent: any;
19
- loadingComponent?: React.ReactNode;
20
- }): {
21
- parentId?: string | undefined;
22
- clientLoader?: (() => Promise<any>) | undefined;
23
- id: string;
24
- path: string | undefined;
25
- index: boolean | undefined;
26
- element: JSX.Element;
27
- };
8
+ }): IClientRoute[];
package/dist/routes.js CHANGED
@@ -20,23 +20,20 @@ export function createClientRoutes(opts) {
20
20
  loadingComponent: opts.loadingComponent,
21
21
  });
22
22
  if (children.length > 0) {
23
- // @ts-ignore
24
23
  route.children = children;
25
24
  // TODO: remove me
26
25
  // compatible with @ant-design/pro-layout
27
- // @ts-ignore
28
26
  route.routes = children;
29
27
  }
30
28
  return route;
31
29
  });
32
30
  }
33
- export function createClientRoute(opts) {
31
+ function createClientRoute(opts) {
34
32
  const { route } = opts;
35
- const { id, path, index, redirect, ...props } = route;
33
+ const { redirect, ...props } = route;
36
34
  return {
37
- id: id,
38
- path: path,
39
- index: index,
35
+ children: [],
36
+ routes: [],
40
37
  element: redirect ? (React.createElement(Navigate, { to: redirect })) : (React.createElement(RouteContext.Provider, { value: {
41
38
  route: opts.route,
42
39
  } },
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export interface IRoute {
2
3
  id: string;
3
4
  path?: string;
@@ -6,6 +7,16 @@ export interface IRoute {
6
7
  redirect?: string;
7
8
  clientLoader?: () => Promise<any>;
8
9
  }
10
+ export interface IClientRoute {
11
+ id: string;
12
+ element: React.ReactNode;
13
+ children: IClientRoute[];
14
+ routes: IClientRoute[];
15
+ path?: string;
16
+ index?: boolean;
17
+ parentId?: string;
18
+ clientLoader?: () => Promise<any>;
19
+ }
9
20
  export interface IRoutesById {
10
21
  [id: string]: IRoute;
11
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/renderer-react",
3
- "version": "4.0.0-rc.20",
3
+ "version": "4.0.0-rc.21",
4
4
  "description": "@umijs/renderer-react",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/renderer-react#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",