fixed unmount)

This commit is contained in:
2020-12-10 20:11:25 +03:00
parent f2209f6708
commit c19d5fc0de
2 changed files with 22 additions and 32 deletions

View File

@@ -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;
}
})
};