Skip to content

Commit eac5322

Browse files
committed
comments
1 parent 01af7d4 commit eac5322

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/index.js

+39-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var hasPushState = history && history.pushState
99
* - {Boolean} hashbang (default: true)
1010
* - {Boolean} pushstate (default: false)
1111
*/
12+
1213
function VueRouter (options) {
1314
this._recognizer = new Recognizer()
1415
this._started = false
@@ -46,6 +47,7 @@ var p = VueRouter.prototype
4647
* - {Function} [before]
4748
* - {Function} [after]
4849
*/
50+
4951
p.on = function (rootPath, config) {
5052
this._addRoute(rootPath, config, [])
5153
}
@@ -55,18 +57,30 @@ p.on = function (rootPath, config) {
5557
*
5658
* @param {Object} config
5759
*/
60+
5861
p.notfound = function (config) {
5962
this._notfoundHandler = [{ handler: config }]
6063
}
6164

65+
/**
66+
* Set redirects.
67+
*
68+
* @param {Object} map
69+
*/
70+
6271
p.redirect = function (map) {
6372
// TODO
6473
// use another recognizer to recognize redirects
6574
}
6675

6776
/**
68-
* Navigate to a given path
77+
* Navigate to a given path.
78+
* The path is assumed to be already decoded, and will
79+
* be resolved against root (if provided)
80+
*
81+
* @param {String} path
6982
*/
83+
7084
p.go = function (path) {
7185
if (this._pushstate) {
7286
// make it relative to root
@@ -88,19 +102,29 @@ p.go = function (path) {
88102
*
89103
* @param {Vue} vm
90104
*/
105+
91106
p.start = function (vm) {
92107
if (this._started) {
93108
return
94109
}
95110
this._started = true
96-
this._vm = vm
111+
this._vm = this._vm || vm
112+
if (!this._vm) {
113+
throw new Error(
114+
'vue-router must be started with a root Vue instance.'
115+
)
116+
}
97117
if (this._pushstate) {
98118
this.initHistoryMode()
99119
} else {
100120
this.initHashMode()
101121
}
102122
}
103123

124+
/**
125+
* Initialize hash mode.
126+
*/
127+
104128
p.initHashMode = function () {
105129
var self = this
106130
this.onRouteChange = function () {
@@ -122,6 +146,10 @@ p.initHashMode = function () {
122146
this.onRouteChange()
123147
}
124148

149+
/**
150+
* Initialize HTML5 history mode.
151+
*/
152+
125153
p.initHistoryMode = function () {
126154
var self = this
127155
this.onRouteChange = function () {
@@ -133,6 +161,10 @@ p.initHistoryMode = function () {
133161
this.onRouteChange()
134162
}
135163

164+
/**
165+
* Stop listening to route changes.
166+
*/
167+
136168
p.stop = function () {
137169
var event = this._pushstate
138170
? 'popstate'
@@ -219,6 +251,11 @@ p._match = function (path) {
219251
this._vm.$set('route', context)
220252
}
221253

254+
/**
255+
* Installation interface.
256+
* Install the necessary directives.
257+
*/
258+
222259
VueRouter.install = function (Vue) {
223260
require('./view')(Vue)
224261
require('./link')(Vue)

src/view.js

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ module.exports = function (Vue) {
6060
this.update(null)
6161
},
6262

63+
// currently duplicating some logic from v-component
64+
// TODO: make it cleaner
6365
build: function () {
6466
var route = this.currentRoute
6567
if (this.keepAlive) {

0 commit comments

Comments
 (0)