@@ -9,6 +9,7 @@ var hasPushState = history && history.pushState
9
9
* - {Boolean} hashbang (default: true)
10
10
* - {Boolean} pushstate (default: false)
11
11
*/
12
+
12
13
function VueRouter ( options ) {
13
14
this . _recognizer = new Recognizer ( )
14
15
this . _started = false
@@ -46,6 +47,7 @@ var p = VueRouter.prototype
46
47
* - {Function} [before]
47
48
* - {Function} [after]
48
49
*/
50
+
49
51
p . on = function ( rootPath , config ) {
50
52
this . _addRoute ( rootPath , config , [ ] )
51
53
}
@@ -55,18 +57,30 @@ p.on = function (rootPath, config) {
55
57
*
56
58
* @param {Object } config
57
59
*/
60
+
58
61
p . notfound = function ( config ) {
59
62
this . _notfoundHandler = [ { handler : config } ]
60
63
}
61
64
65
+ /**
66
+ * Set redirects.
67
+ *
68
+ * @param {Object } map
69
+ */
70
+
62
71
p . redirect = function ( map ) {
63
72
// TODO
64
73
// use another recognizer to recognize redirects
65
74
}
66
75
67
76
/**
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
69
82
*/
83
+
70
84
p . go = function ( path ) {
71
85
if ( this . _pushstate ) {
72
86
// make it relative to root
@@ -88,19 +102,29 @@ p.go = function (path) {
88
102
*
89
103
* @param {Vue } vm
90
104
*/
105
+
91
106
p . start = function ( vm ) {
92
107
if ( this . _started ) {
93
108
return
94
109
}
95
110
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
+ }
97
117
if ( this . _pushstate ) {
98
118
this . initHistoryMode ( )
99
119
} else {
100
120
this . initHashMode ( )
101
121
}
102
122
}
103
123
124
+ /**
125
+ * Initialize hash mode.
126
+ */
127
+
104
128
p . initHashMode = function ( ) {
105
129
var self = this
106
130
this . onRouteChange = function ( ) {
@@ -122,6 +146,10 @@ p.initHashMode = function () {
122
146
this . onRouteChange ( )
123
147
}
124
148
149
+ /**
150
+ * Initialize HTML5 history mode.
151
+ */
152
+
125
153
p . initHistoryMode = function ( ) {
126
154
var self = this
127
155
this . onRouteChange = function ( ) {
@@ -133,6 +161,10 @@ p.initHistoryMode = function () {
133
161
this . onRouteChange ( )
134
162
}
135
163
164
+ /**
165
+ * Stop listening to route changes.
166
+ */
167
+
136
168
p . stop = function ( ) {
137
169
var event = this . _pushstate
138
170
? 'popstate'
@@ -219,6 +251,11 @@ p._match = function (path) {
219
251
this . _vm . $set ( 'route' , context )
220
252
}
221
253
254
+ /**
255
+ * Installation interface.
256
+ * Install the necessary directives.
257
+ */
258
+
222
259
VueRouter . install = function ( Vue ) {
223
260
require ( './view' ) ( Vue )
224
261
require ( './link' ) ( Vue )
0 commit comments