fixed unmount)
This commit is contained in:
48
src/main.ts
48
src/main.ts
@@ -14,27 +14,8 @@ const systemJSImport = async (requestUrl: string) => {
|
||||
return { component, mount, unmount }
|
||||
}
|
||||
|
||||
// const defaultNavigations = {
|
||||
// login: '/login',
|
||||
// main: '/main',
|
||||
// news: '/news',
|
||||
// org: '/org',
|
||||
// sections: '/sections',
|
||||
// 'news.details': '/news/{{id}}',
|
||||
// 'org.details': '/org/{{name}}',
|
||||
// 'sections.details': '/sections/{{name}}'
|
||||
// }
|
||||
|
||||
// const defaultApps = {
|
||||
// login: { version: '1.0.0', name: 'login' },
|
||||
// main: { version: '1.0.1', name: 'main' },
|
||||
// news: { version: '1.0.0', name: 'news' },
|
||||
// org: { version: '1.0.0', name: 'org' },
|
||||
// sections: { version: '1.0.0', name: 'sections' }
|
||||
// }
|
||||
|
||||
export default async ({ apps: rawApps, navigations, config, features }) => {
|
||||
defineVirtualModule({ navigations, config, features })
|
||||
export default async ({ apps: rawApps, navigations, config }) => {
|
||||
defineVirtualModule({ navigations, config })
|
||||
|
||||
const apps = new Apps(rawApps)
|
||||
|
||||
@@ -42,22 +23,31 @@ export default async ({ apps: rawApps, navigations, config, features }) => {
|
||||
|
||||
let prevPathname = window.location.pathname
|
||||
|
||||
const app = apps.findApp(history.location.pathname)
|
||||
async function getApp() {
|
||||
const app = apps.findApp(history.location.pathname)
|
||||
|
||||
const publicPath = `/${app.name}/${app.version}`
|
||||
const publicPath = `/${app.name}/${app.version}`
|
||||
|
||||
__webpack_public_path__ = `${config.baseUrl}${publicPath}${__webpack_public_path__}`
|
||||
|
||||
const appPath = `${config.baseUrl}${publicPath}/index.js`
|
||||
|
||||
const { component, mount, unmount } = await systemJSImport(appPath);
|
||||
|
||||
__webpack_public_path__ = `${config.baseUrl}${publicPath}${__webpack_public_path__}`
|
||||
|
||||
const appPath = `${config.baseUrl}${publicPath}/index.js`
|
||||
|
||||
const { component, mount, unmount } = await systemJSImport(appPath);
|
||||
return { component, mount, unmount };
|
||||
}
|
||||
|
||||
let { component, mount, unmount } = await getApp()
|
||||
mount(component.default);
|
||||
|
||||
history.listen((location) => {
|
||||
history.listen(async (location) => {
|
||||
if (location.pathname !== prevPathname) {
|
||||
prevPathname = location.pathname
|
||||
unmount()
|
||||
|
||||
const nextApp = await getApp();
|
||||
nextApp.mount(nextApp.component.default)
|
||||
unmount = nextApp.unmount;
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user