Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_mount() {
// 通过container来指明挂载点
this.app = new App({container: this.refs.container});
}
import 'core-js/es6/promise';
import './main';
import router from './router';
import createHistory from 'history/createBrowserHistory';
import App from 'kpc/components/app';
import Link from 'kpc/components/link';
import serverStyleCleanup from 'node-style-loader/clientCleanup';
const history = createHistory();
const $app = new App({container: document.getElementById('page'), ssr: true});
$app.history = history;
Link.history = history;
window.$app = $app;
let unlisten;
function init(router) {
if (unlisten) unlisten();
unlisten = history.listen(async ({pathname}, action) => {
$app.showLoading();
const {Page, data} = await router.resolve({pathname});
await $app.load(Page, data, serverStyleCleanup);
});
history.replace(location);
}
return router.resolve({pathname: path}).then(({Page, data}) => {
const $app = new App();
return $app.render(Page, data).then(() => {
return {
content: $app.toString(),
style: collectInitial(),
};
}).catch(e => {
console.log(e.stack);
});
});
}