Skip to content

Commit c3fdd5c

Browse files
committed
use more consistent override
1 parent d3c7d71 commit c3fdd5c

File tree

3 files changed

+36
-52
lines changed

3 files changed

+36
-52
lines changed

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import util, { warn, mapParams } from './util'
2-
import initMixin from './mixin'
2+
import applyOverride from './override'
33
import Recognizer from 'route-recognizer'
44
import Route from './route'
55
import Transition from './transition'
@@ -563,7 +563,7 @@ Router.install = function (externalVue) {
563563
return
564564
}
565565
Vue = externalVue
566-
initMixin(Vue)
566+
applyOverride(Vue)
567567
View(Vue)
568568
Link(Vue)
569569
util.Vue = Vue

src/mixin.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/override.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export default function (Vue) {
2+
3+
const _ = Vue.util
4+
5+
const init = Vue.prototype._init
6+
Vue.prototype._init = function (options) {
7+
const root = options._parent || options.parent || this
8+
const route = root.$route
9+
if (route) {
10+
route.router._children.push(this)
11+
if (!this.$route) {
12+
if (this._defineMeta) {
13+
// 0.12
14+
this._defineMeta('$route', route)
15+
} else {
16+
// 1.0
17+
_.defineReactive(this, '$route', route)
18+
}
19+
}
20+
}
21+
init.call(this, options)
22+
}
23+
24+
const destroy = Vue.prototype._destroy
25+
Vue.prototype._destroy = function () {
26+
if (!this._isBeingDestroyed) {
27+
const route = this.$root.$route
28+
if (route) {
29+
route.router._children.$remove(this)
30+
}
31+
destroy.apply(this, arguments)
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)