Skip to content

Commit 01af7d4

Browse files
committed
handle root better
1 parent 971bda1 commit 01af7d4

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

src/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ p.redirect = function (map) {
6969
*/
7070
p.go = function (path) {
7171
if (this._pushstate) {
72+
// make it relative to root
73+
path = this._root
74+
? this._root + '/' + path.replace(/^\//, '')
75+
: path
7276
history.pushState({}, '', path)
7377
this._match(path)
7478
} else {
@@ -183,7 +187,11 @@ p._match = function (path) {
183187
}
184188
this._currentPath = path
185189
// normalize against root
186-
if (this._root && path.indexOf(this._root) === 0) {
190+
if (
191+
this._pushstate &&
192+
this._root &&
193+
path.indexOf(this._root) === 0
194+
) {
187195
path = path.slice(this._root.length)
188196
}
189197
var matched = this._recognizer.recognize(path)

src/link.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ module.exports = function (Vue) {
77

88
bind: function () {
99
var vm = this.vm
10-
// normalize leading slash
11-
var href = '/' + this.expression.replace(/^\//, '')
10+
var href = this.expression
1211
if (this.el.tagName === 'A') {
1312
this.el.href = href
1413
}
1514
this.handler = function (e) {
1615
e.preventDefault()
17-
var router = vm.route._router
18-
router.go((router._root || '') + href)
16+
router.go(href)
1917
}
2018
this.el.addEventListener('click', this.handler)
2119
},

src/view.js

+4-14
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,14 @@ module.exports = function (Vue) {
1313
_.extend(viewDef, {
1414

1515
bind: function () {
16-
// implicitly pass down route context
17-
// using v-with
18-
this.el.setAttribute(
19-
Vue.config.prefix + 'with',
20-
'route:route'
21-
)
22-
// set currentView ref
23-
this.el.setAttribute(
24-
Vue.config.prefix + 'ref',
25-
'currentView'
26-
)
27-
// force dynamic directive
28-
this._isDynamicLiteral = true
2916
// react to route change
3017
this.currentRoute = null
3118
this.currentComponentId = null
3219
this.onRouteChange = _.bind(this.onRouteChange, this)
3320
this.unwatch = this.vm.$watch('route', this.onRouteChange)
21+
// force dynamic directive so v-component doesn't
22+
// attempt to build right now
23+
this._isDynamicLiteral = true
3424
// finally, init by delegating to v-component
3525
component.bind.call(this)
3626
if (this.vm.route) {
@@ -60,7 +50,7 @@ module.exports = function (Vue) {
6050
this.currentComponentId = segment.handler.component
6151
this.update(segment.handler.component)
6252
} else if (this.childVM) {
63-
// possible params change
53+
// update route context
6454
this.childVM.route = route
6555
}
6656
},

0 commit comments

Comments
 (0)