Skip to content

Commit c235f0d

Browse files
committed
fix: Router initialization
1 parent 0f18932 commit c235f0d

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/vue-router.common.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,33 @@ export const createRouter = (
2323
vueRouterOptions: NSVueRouterOptions,
2424
routerOptions: RouterServiceOptions = {}
2525
) => {
26-
const vm = routerOptions.vm || (Vue as any).prototype;
26+
const vm = routerOptions.vm || Vue;
27+
const proto = (Vue as any).prototype;
2728

2829
const router = new RouterService(vueRouterOptions, {
2930
frame: Frame,
30-
vm,
31+
vm: proto,
3132
...routerOptions,
3233
});
3334

3435
// Vue 3 compatibility
35-
if (vm.config && vm.config.globalProperties) {
36-
vm.config.globalProperties.$routeTo = router.push.bind(router);
37-
vm.config.globalProperties.$routeBack = router.back.bind(router);
38-
vm.config.globalProperties.$router = router;
36+
if (proto.config && proto.config.globalProperties) {
37+
proto.config.globalProperties.$routeTo = router.push.bind(router);
38+
proto.config.globalProperties.$routeBack = router.back.bind(router);
39+
proto.config.globalProperties.$router = router;
3940
} else {
40-
vm.$routeTo = router.push.bind(router);
41-
vm.$routeBack = router.back.bind(router);
42-
vm.$router = router;
41+
proto.$routeTo = router.push.bind(router);
42+
proto.$routeBack = router.back.bind(router);
43+
proto.$router = router;
4344
}
4445

4546
if (vm.mixin) {
4647
vm.mixin(routerMixin);
4748
}
4849

4950
// Register Action Dispatcher if store is available
50-
if (vm.$store) {
51-
registerActionDispatcher(router, vm.$store);
51+
if (proto.$store) {
52+
registerActionDispatcher(router, proto.$store);
5253
}
5354

5455
return router;

0 commit comments

Comments
 (0)