fix m.route.link and m.route.set history replacement
This commit is contained in:
parent
08a4442814
commit
992aa30ccc
11 changed files with 113 additions and 203 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue