You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.9 KiB

"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var _react = require('react'); var React = _interopRequireWildcard(_react);
var _reactdom = require('react-dom'); var ReactDOM = _interopRequireWildcard(_reactdom);
var _runtime = require('@umijs/runtime');
function getRootContainer(opts) {
for (const route of opts.routes) {
if (route.path === opts.path)
return route.component;
}
}
function renderClient(opts) {
let path = opts.path;
if (!path) {
path = window.g_path;
}
for (const route of opts.routes) {
if (route.routes) {
throw new Error(`Render failed, child routes is not supported in mpa renderer.`);
}
}
const RouteComponent = getRootContainer({routes: opts.routes, path});
if (!RouteComponent) {
throw new Error(`Render failed, route of path ${path} not found.`);
}
const rootContainer = opts.plugin.applyPlugins({
type: _runtime.ApplyPluginsType.modify,
key: "rootContainer",
initialValue: /* @__PURE__ */ React.createElement(RouteComponent, {
history: opts.history,
routes: opts.routes,
plugin: opts.plugin,
defaultTitle: opts.defaultTitle
}),
args: {
history: opts.history,
routes: opts.routes,
plugin: opts.plugin
}
});
if (opts.rootElement) {
const rootElement = typeof opts.rootElement === "string" ? document.getElementById(opts.rootElement) : opts.rootElement;
const callback = opts.callback || (() => {
});
ReactDOM[window.g_useSSR ? "hydrate" : "render"](rootContainer, rootElement, callback);
} else {
return rootContainer;
}
} exports.renderClient = renderClient;