fix m.route.link and m.route.set history replacement

This commit is contained in:
Leo Horie 2016-12-06 23:29:15 -05:00
parent 08a4442814
commit 992aa30ccc
11 changed files with 113 additions and 203 deletions

View file

@ -41,11 +41,23 @@ module.exports = function($window, redrawService) {
redrawService.subscribe(root, run)
}
route.set = function(path, data, options) {
if (resolve != null) options = {replace: true}
resolve = null
routeService.setPath(path, data, options)
}
route.get = function() {return currentPath}
route.prefix = routeService.setPrefix
route.link = routeService.link
route.prefix = function(prefix) {routeService.prefix = prefix}
route.link = function(vnode) {
vnode.dom.setAttribute("href", routeService.prefix + vnode.attrs.href)
vnode.dom.onclick = function(e) {
if (e.ctrlKey || e.metaKey || e.shiftKey || e.which === 2) return
e.preventDefault()
e.redraw = false
var href = this.getAttribute("href")
if (href.indexOf(routeService.prefix) === 0) href = href.slice(routeService.prefix.length)
route.set(href, undefined, undefined)
}
}
return route
}

View file

@ -358,7 +358,7 @@ o.spec("route", function() {
})
callAsync(function() {
o(oninit.callCount).equals(1)
route.set('/def')
route.set("/def")
callAsync(function() {
o(oninit.callCount).equals(2)
done()
@ -897,12 +897,14 @@ o.spec("route", function() {
},
})
callAsync(function() {
callAsync(function() {
o(rendered).equals(false)
o(resolved).equals("b")
done()
callAsync(function() { // tick for popstate for /a
callAsync(function() { // tick for promise in onmatch
callAsync(function() { // tick for onpopstate for /b
o(rendered).equals(false)
o(resolved).equals("b")
done()
})
})
})
})