m.route.get() returns the last fully resolved route (fix #1276), change RouteResolver.onmatch() signature according to #1277
This commit is contained in:
parent
419897f72c
commit
a34685d7a4
2 changed files with 15 additions and 14 deletions
|
|
@ -5,7 +5,7 @@ var coreRouter = require("../router/router")
|
||||||
|
|
||||||
module.exports = function($window, mount) {
|
module.exports = function($window, mount) {
|
||||||
var router = coreRouter($window)
|
var router = coreRouter($window)
|
||||||
var globalId, currentComponent, currentRender, currentArgs
|
var globalId, currentComponent, currentRender, currentArgs, currentPath
|
||||||
|
|
||||||
var RouteComponent = {view: function() {
|
var RouteComponent = {view: function() {
|
||||||
return currentRender(Vnode(currentComponent, null, currentArgs, undefined, undefined, undefined))
|
return currentRender(Vnode(currentComponent, null, currentArgs, undefined, undefined, undefined))
|
||||||
|
|
@ -32,6 +32,7 @@ module.exports = function($window, mount) {
|
||||||
currentComponent = component != null ? component: isResolver ? "div" : payload
|
currentComponent = component != null ? component: isResolver ? "div" : payload
|
||||||
currentRender = render
|
currentRender = render
|
||||||
currentArgs = args
|
currentArgs = args
|
||||||
|
currentPath = path
|
||||||
|
|
||||||
root.redraw(true)
|
root.redraw(true)
|
||||||
}
|
}
|
||||||
|
|
@ -42,8 +43,8 @@ module.exports = function($window, mount) {
|
||||||
if (typeof payload.render === "function") render = payload.render.bind(payload)
|
if (typeof payload.render === "function") render = payload.render.bind(payload)
|
||||||
if (typeof payload.onmatch === "function") onmatch = payload.onmatch
|
if (typeof payload.onmatch === "function") onmatch = payload.onmatch
|
||||||
}
|
}
|
||||||
|
|
||||||
onmatch.call(payload, {attrs: args}, resolve)
|
onmatch.call(payload, resolve, args, path)
|
||||||
}, function() {
|
}, function() {
|
||||||
router.setPath(defaultRoute, null, {replace: true})
|
router.setPath(defaultRoute, null, {replace: true})
|
||||||
})
|
})
|
||||||
|
|
@ -51,7 +52,7 @@ module.exports = function($window, mount) {
|
||||||
route.link = router.link
|
route.link = router.link
|
||||||
route.prefix = router.setPrefix
|
route.prefix = router.setPrefix
|
||||||
route.set = router.setPath
|
route.set = router.setPath
|
||||||
route.get = router.getPath
|
route.get = function() {return currentPath}
|
||||||
|
|
||||||
return route
|
return route
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -238,11 +238,11 @@ o.spec("route", function() {
|
||||||
$window.location.href = prefix + "/"
|
$window.location.href = prefix + "/"
|
||||||
route(root, "/abc", {
|
route(root, "/abc", {
|
||||||
"/:id" : {
|
"/:id" : {
|
||||||
onmatch: function(vnode, resolve) {
|
onmatch: function(resolve, args, requestedPath) {
|
||||||
matchCount++
|
matchCount++
|
||||||
|
|
||||||
o(vnode.attrs.id).equals("abc")
|
o(args.id).equals("abc")
|
||||||
o(route.get()).equals("/abc")
|
o(requestedPath).equals("/abc")
|
||||||
|
|
||||||
resolve(Component)
|
resolve(Component)
|
||||||
},
|
},
|
||||||
|
|
@ -276,11 +276,11 @@ o.spec("route", function() {
|
||||||
$window.location.href = prefix + "/"
|
$window.location.href = prefix + "/"
|
||||||
route(root, "/abc", {
|
route(root, "/abc", {
|
||||||
"/:id" : {
|
"/:id" : {
|
||||||
onmatch: function(vnode, resolve) {
|
onmatch: function(resolve, args, requestedPath) {
|
||||||
matchCount++
|
matchCount++
|
||||||
|
|
||||||
o(vnode.attrs.id).equals("abc")
|
o(args.id).equals("abc")
|
||||||
o(route.get()).equals("/abc")
|
o(requestedPath).equals("/abc")
|
||||||
|
|
||||||
resolve(Component)
|
resolve(Component)
|
||||||
},
|
},
|
||||||
|
|
@ -374,7 +374,7 @@ o.spec("route", function() {
|
||||||
$window.location.href = prefix + "/"
|
$window.location.href = prefix + "/"
|
||||||
route(root, "/", {
|
route(root, "/", {
|
||||||
"/" : {
|
"/" : {
|
||||||
onmatch: function(vnode, resolve) {
|
onmatch: function(resolve) {
|
||||||
matchCount++
|
matchCount++
|
||||||
resolve(Component)
|
resolve(Component)
|
||||||
},
|
},
|
||||||
|
|
@ -458,7 +458,7 @@ o.spec("route", function() {
|
||||||
$window.location.href = prefix + "/"
|
$window.location.href = prefix + "/"
|
||||||
route(root, "/", {
|
route(root, "/", {
|
||||||
"/": {
|
"/": {
|
||||||
onmatch: function(vnode, resolve) {
|
onmatch: function(resolve) {
|
||||||
resolve(A)
|
resolve(A)
|
||||||
resolve(B)
|
resolve(B)
|
||||||
callAsync(function() {resolve(C)})
|
callAsync(function() {resolve(C)})
|
||||||
|
|
@ -530,7 +530,7 @@ o.spec("route", function() {
|
||||||
o("m.route.set(m.route.get()) re-runs the resolution logic (#1180)", function(done, timeout){
|
o("m.route.set(m.route.get()) re-runs the resolution logic (#1180)", function(done, timeout){
|
||||||
timeout(FRAME_BUDGET * 3)
|
timeout(FRAME_BUDGET * 3)
|
||||||
|
|
||||||
var onmatch = o.spy(function(vnode, resolve){resolve()})
|
var onmatch = o.spy(function(resolve){resolve()})
|
||||||
|
|
||||||
$window.location.href = prefix + "/"
|
$window.location.href = prefix + "/"
|
||||||
route(root, '/', {
|
route(root, '/', {
|
||||||
|
|
@ -612,7 +612,7 @@ o.spec("route", function() {
|
||||||
$window.location.href = prefix + "/"
|
$window.location.href = prefix + "/"
|
||||||
route(root, "/a", {
|
route(root, "/a", {
|
||||||
"/a": {
|
"/a": {
|
||||||
onmatch: function(vnode, resolve) {
|
onmatch: function(resolve) {
|
||||||
setTimeout(resolve, 20)
|
setTimeout(resolve, 20)
|
||||||
},
|
},
|
||||||
render: function(vnode) {resolved = "a"}
|
render: function(vnode) {resolved = "a"}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue