@umijs/renderer-react 4.0.0-beta.13 → 4.0.0-beta.17

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.
package/dist/browser.d.ts CHANGED
@@ -1,7 +1,10 @@
1
+ import { History } from 'history';
1
2
  import { IRouteComponents, IRoutesById } from './types';
2
3
  export declare function renderClient(opts: {
3
4
  rootElement?: HTMLElement;
4
5
  routes: IRoutesById;
5
6
  routeComponents: IRouteComponents;
6
7
  pluginManager: any;
8
+ basename?: string;
9
+ history: History;
7
10
  }): void;
package/dist/browser.js CHANGED
@@ -1,42 +1,49 @@
1
- // @ts-ignore
2
- import { createBrowserHistory } from 'history';
3
1
  import React from 'react';
4
2
  import ReactDOM from 'react-dom';
5
3
  import { Router, useRoutes } from 'react-router-dom';
6
4
  import { AppContext, useAppData } from './appContext';
7
5
  import { createClientRoutes } from './routes';
8
6
  function BrowserRoutes(props) {
9
- const historyRef = React.useRef();
10
- if (historyRef.current == null) {
11
- historyRef.current = createBrowserHistory({ window });
12
- }
13
- const history = historyRef.current;
7
+ const { history } = props;
14
8
  const [state, setState] = React.useState({
15
9
  action: history.action,
16
10
  location: history.location,
17
11
  });
18
12
  React.useLayoutEffect(() => history.listen(setState), [history]);
19
- return (React.createElement(Router, { navigator: history, location: state.location }, props.children));
13
+ React.useLayoutEffect(() => history.listen((location, action) => {
14
+ props.pluginManager.applyPlugins({
15
+ key: 'onRouteChange',
16
+ type: 'event',
17
+ args: {
18
+ routes: props.routes,
19
+ clientRoutes: props.clientRoutes,
20
+ location,
21
+ action,
22
+ },
23
+ });
24
+ }), [history, props.routes, props.clientRoutes]);
25
+ return (React.createElement(Router, { navigator: history, location: state.location, basename: props.basename }, props.children));
20
26
  }
21
27
  function Routes() {
22
28
  const { clientRoutes } = useAppData();
23
29
  return useRoutes(clientRoutes);
24
30
  }
25
31
  export function renderClient(opts) {
32
+ const basename = opts.basename || '/';
26
33
  const rootElement = opts.rootElement || document.getElementById('root');
27
34
  const clientRoutes = createClientRoutes({
28
35
  routesById: opts.routes,
29
36
  routeComponents: opts.routeComponents,
30
37
  });
31
- let rootContainer = (React.createElement(BrowserRoutes, null,
38
+ let rootContainer = (React.createElement(BrowserRoutes, { basename: basename, pluginManager: opts.pluginManager, routes: opts.routes, clientRoutes: clientRoutes, history: opts.history },
32
39
  React.createElement(Routes, null)));
33
40
  for (const key of [
41
+ // Lowest to the highest priority
34
42
  'innerProvider',
35
43
  'i18nProvider',
36
44
  'accessProvider',
37
45
  'dataflowProvider',
38
46
  'outerProvider',
39
- // Highest priority
40
47
  'rootContainer',
41
48
  ]) {
42
49
  rootContainer = opts.pluginManager.applyPlugins({
@@ -52,6 +59,7 @@ export function renderClient(opts) {
52
59
  clientRoutes,
53
60
  pluginManager: opts.pluginManager,
54
61
  rootElement: opts.rootElement,
62
+ basename,
55
63
  } }, rootContainer));
56
64
  // @ts-ignore
57
65
  if (ReactDOM.createRoot) {
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { createBrowserHistory, createHashHistory, createMemoryHistory, History, } from 'history';
1
2
  export { createSearchParams, Link, matchPath, matchRoutes, NavLink, Outlet, useLocation, useMatch, useNavigate, useOutlet, useParams, useResolvedPath, useRoutes, useSearchParams, } from 'react-router-dom';
2
3
  export { useAppData } from './appContext';
3
4
  export { renderClient } from './browser';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { createBrowserHistory, createHashHistory, createMemoryHistory, } from 'history';
1
2
  export { createSearchParams, Link, matchPath, matchRoutes, NavLink, Outlet, useLocation, useMatch, useNavigate, useOutlet, useParams, useResolvedPath, useRoutes, useSearchParams, } from 'react-router-dom';
2
3
  export { useAppData } from './appContext';
3
4
  export { renderClient } from './browser';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/renderer-react",
3
- "version": "4.0.0-beta.13",
3
+ "version": "4.0.0-beta.17",
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",
@@ -26,8 +26,8 @@
26
26
  "react-router-dom": "6.1.1"
27
27
  },
28
28
  "devDependencies": {
29
- "react": "18.0.0-rc.0",
30
- "react-dom": "18.0.0-rc.0"
29
+ "react": "17.0.2",
30
+ "react-dom": "17.0.2"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "react": ">=16.8",