@@ -2,8 +2,9 @@ import _Vue from 'vue';
22import { Route, RawLocation } from 'vue-router';
33import dynamicComponent from './ability/dynamicComponent';
44import dynamicComponentState from './ability/dynamicComponent/storeModule';
5- import eventBus from './ability/eventBus';
6- import moduleLoader from './ability/moduleLoader';
5+ import createEventBus from './ability/eventBus';
6+ import createModuleLoader from './ability/moduleLoader';
7+ import createComponentLoader from './ability/componentLoader';
78import { UseOptions } from '../types';
89
910export default function install(Vue: typeof _Vue, options: UseOptions = {}) {
@@ -23,11 +24,15 @@ export default function install(Vue: typeof _Vue, options: UseOptions = {}) {
2324
2425 Object.defineProperties(Vue.prototype, {
2526 $eventBus: {
26- value: eventBus (Vue),
27+ value: createEventBus (Vue),
2728 writable: false,
2829 },
2930 $moduleLoader: {
30- value: moduleLoader(Vue, vm.status),
31+ value: createModuleLoader(Vue, vm.status),
32+ writable: false,
33+ },
34+ $componentLoader: {
35+ value: createComponentLoader(),
3136 writable: false,
3237 },
3338 });
@@ -47,7 +52,11 @@ export default function install(Vue: typeof _Vue, options: UseOptions = {}) {
4752 // router
4853 // 解决动态路由404问题
4954 if (router) {
50- const resolveRoute = (to: Route, next: (to?: RawLocation | false | ((vm: _Vue) => void) | void) => void) => {
55+ const resolveRoute = (
56+ to: Route,
57+ from: Route,
58+ next: (to?: RawLocation | false | ((vm: _Vue) => void) | void) => void,
59+ ) => {
5160 const fullPath = to.redirectedFrom || to.fullPath;
5261
5362 const { resolved, location } = router.resolve(fullPath);
@@ -61,17 +70,17 @@ export default function install(Vue: typeof _Vue, options: UseOptions = {}) {
6170 };
6271
6372 router.beforeEach((to, from, next) => {
64- if (!to.name || to.name === '404' || to.name === 'page-not-found') {
73+ if (!to.name || to.name === '404' || to.name === 'page-not-found' || to.path === '*' ) {
6574 // 模块已经被加载完成, 但由于在其之前添加 beforeEach 阻止时间过长,vm.$watch还没开始监听
6675 if (vm.status.current) {
67- resolveRoute(to, next);
76+ resolveRoute(to, from, next);
6877 }
6978 vm.$watch(
7079 () => vm.status.current,
7180 (newVal, oldVal) => {
7281 // false => true
7382 if (newVal && !oldVal) {
74- resolveRoute(to, next);
83+ resolveRoute(to, from, next);
7584 }
7685 },
7786 );
0 commit comments