up bootstrap
This commit is contained in:
+46
@@ -0,0 +1,46 @@
|
||||
import "systemjs/dist/s";
|
||||
import "systemjs/dist/extras/amd";
|
||||
import "systemjs/dist/extras/named-register";
|
||||
import "systemjs/dist/extras/named-exports";
|
||||
import "systemjs/dist/extras/transform";
|
||||
import { createBrowserHistory } from 'history'
|
||||
|
||||
declare var System: {
|
||||
import(string): Promise<any>
|
||||
}
|
||||
|
||||
const systemJSImport = async (requestUrl: string) => {
|
||||
const { default: component, mount, unmount } = await System.import(
|
||||
requestUrl
|
||||
)
|
||||
return { component, mount, unmount }
|
||||
}
|
||||
|
||||
const getApp = (apps, path) => {
|
||||
const searchKey = path.substr(1)
|
||||
return `./${searchKey}/${apps[searchKey].version}/index.js`
|
||||
}
|
||||
|
||||
export default async ({ apps, navigations, config }) => {
|
||||
|
||||
const history = createBrowserHistory()
|
||||
|
||||
let prevPathname = window.location.pathname
|
||||
|
||||
/* tslint:disable-next-line */
|
||||
__webpack_public_path__ = `/static${__webpack_public_path__}`
|
||||
|
||||
const app = getApp(apps, history.location.pathname)
|
||||
|
||||
const { component, mount, unmount } = await systemJSImport(app);
|
||||
|
||||
mount(component.default);
|
||||
|
||||
|
||||
history.listen((location) => {
|
||||
if (location.pathname !== prevPathname) {
|
||||
prevPathname = location.pathname
|
||||
unmount()
|
||||
}
|
||||
})
|
||||
};
|
||||
Reference in New Issue
Block a user