Skip to content

Commit bf33688

Browse files
committed
auto install on global Vue
1 parent 967a651 commit bf33688

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/index.js

+23-10
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,6 @@ p._match = function (path) {
275275
this._vm.$set('route', context)
276276
}
277277

278-
/**
279-
* Installation interface.
280-
* Install the necessary directives.
281-
*/
282-
283-
VueRouter.install = function (Vue) {
284-
require('./view')(Vue)
285-
require('./link')(Vue)
286-
}
287-
288278
/**
289279
* Set current hash
290280
*
@@ -301,4 +291,27 @@ function setHash (hash, replace) {
301291
}
302292
}
303293

294+
/**
295+
* Installation interface.
296+
* Install the necessary directives.
297+
*/
298+
299+
var installed = false
300+
VueRouter.install = function (Vue) {
301+
if (installed) {
302+
Vue.util.warn && Vue.util.warn(
303+
'vue-router has already been installed.'
304+
)
305+
return
306+
}
307+
installed = true
308+
require('./view')(Vue)
309+
require('./link')(Vue)
310+
}
311+
312+
// Auto-install if loaded
313+
if (typeof Vue !== 'undefined') {
314+
Vue.use(VueRouter)
315+
}
316+
304317
module.exports = VueRouter

0 commit comments

Comments
 (0)