diff --git a/packages/icestark-app/src/index.ts b/packages/icestark-app/src/index.ts index 0cf77553..72d5b973 100644 --- a/packages/icestark-app/src/index.ts +++ b/packages/icestark-app/src/index.ts @@ -1,5 +1,5 @@ export { default as getMountNode } from './getMountNode'; -export { default as renderNotFound } from './renderNotFound'; +export { default as renderError, renderNotFound } from './renderError'; export { default as getBasename } from './getBasename'; export { default as setBasename } from './setBasename'; export { default as registerAppEnter } from './registerAppEnter'; diff --git a/packages/icestark-app/src/renderNotFound.ts b/packages/icestark-app/src/renderError.ts similarity index 63% rename from packages/icestark-app/src/renderNotFound.ts rename to packages/icestark-app/src/renderError.ts index 20a13194..dedd6412 100644 --- a/packages/icestark-app/src/renderNotFound.ts +++ b/packages/icestark-app/src/renderError.ts @@ -1,31 +1,44 @@ -import { getCache } from './cache'; - -/** - * CustomEvent Polyfill for IE - */ -(function () { - if (typeof (window as any).CustomEvent === 'function') return false; - - function CustomEvent(event, params) { - params = params || { bubbles: false, cancelable: false, detail: null }; - const evt = document.createEvent('CustomEvent'); - evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); - return evt; - } - - (window as any).CustomEvent = CustomEvent; -})(); - -/** - * Trigger customEvent icestark:not-found - */ -export default () => { - if (getCache('root')) { - window.dispatchEvent(new CustomEvent('icestark:not-found')); - - // Compatible processing return renderNotFound(); - return null; - } - - return 'Current sub-application is running independently'; -}; +import { getCache } from './cache'; + +/** + * CustomEvent Polyfill for IE + */ +(function () { + if (typeof (window as any).CustomEvent === 'function') return false; + + function CustomEvent(event, params) { + params = params || { bubbles: false, cancelable: false, detail: null }; + const evt = document.createEvent('CustomEvent'); + evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); + return evt; + } + + (window as any).CustomEvent = CustomEvent; +})(); + +/** + * Trigger customEvent icestark:error + */ +export default (error) => { + if (getCache('root')) { + window.dispatchEvent(new CustomEvent('icestark:error', { bubbles: false, cancelable: false, detail: error })); + // Compatible processing return renderError(); + return null; + } + + return 'Current sub-application is running independently'; +}; + +/** + * Trigger customEvent icestark:not-found + */ +export const renderNotFound = () => { + if (getCache('root')) { + window.dispatchEvent(new CustomEvent('icestark:not-found')); + + // Compatible processing return renderNotFound(); + return null; + } + + return 'Current sub-application is running independently'; +}; diff --git a/packages/icestark/package.json b/packages/icestark/package.json index e87d4e28..2b9dd822 100644 --- a/packages/icestark/package.json +++ b/packages/icestark/package.json @@ -1,6 +1,6 @@ { "name": "@ice/stark", - "version": "2.7.5", + "version": "2.7.6", "description": "Icestark is a JavaScript library for multiple projects, Ice workbench solution.", "scripts": { "build": "rm -rf lib && tsc", diff --git a/packages/icestark/src/AppRoute.tsx b/packages/icestark/src/AppRoute.tsx index 84558289..e10a639f 100644 --- a/packages/icestark/src/AppRoute.tsx +++ b/packages/icestark/src/AppRoute.tsx @@ -146,7 +146,8 @@ export default class AppRoute extends React.Component this.renderChild()); } }; diff --git a/packages/icestark/src/AppRouter.tsx b/packages/icestark/src/AppRouter.tsx index 6c7426b1..e43e0007 100644 --- a/packages/icestark/src/AppRouter.tsx +++ b/packages/icestark/src/AppRouter.tsx @@ -47,7 +47,9 @@ export default class AppRouter extends React.Component {}, // eslint-disable-next-line react/jsx-filename-extension - ErrorComponent: ({ err }: { err: string | Error}) =>
{ typeof err === 'string' ? err : err?.message }
, + ErrorComponent: ({ err }: { err: string | Error }) => ( +
{typeof err === 'string' ? err : err?.message}
+ ), LoadingComponent:
Loading...
, NotFoundComponent:
NotFound
, onAppEnter: () => {}, @@ -84,16 +86,17 @@ export default class AppRouter extends React.Component { + this.triggerError(e.detail); + }; + triggerNotFound = (): void => { // if AppRouter is unmounted, cancel all operations if (this.unmounted) return; @@ -173,6 +184,14 @@ export default class AppRouter extends React.Component { + this.props.onAppEnter(app); + if (this.props.prefetch) { + // 预加载场景需要将loading提升,否则会由于脚本阻塞进程,导致loading失效 + this.setState({ appLoading: app.name }); + } + }; + loadingApp = (app: AppConfig) => { if (this.unmounted) return; this.props.onLoadingApp(app); @@ -256,7 +275,7 @@ export default class AppRouter extends React.Component