Merge pull request #1131 from 2is10/route
Fixing m.route() after a canceled navigation (#1126)
This commit is contained in:
commit
b848655d8b
2 changed files with 14 additions and 5 deletions
17
mithril.js
17
mithril.js
|
|
@ -1435,8 +1435,13 @@
|
||||||
removeRootElement(root, index)
|
removeRootElement(root, index)
|
||||||
}
|
}
|
||||||
return controllers[index]
|
return controllers[index]
|
||||||
} else if (component == null) {
|
} else {
|
||||||
removeRootElement(root, index)
|
if (component == null) {
|
||||||
|
removeRootElement(root, index)
|
||||||
|
}
|
||||||
|
if (previousRoute) {
|
||||||
|
currentRoute = previousRoute
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1570,7 +1575,7 @@
|
||||||
var modes = {pathname: "", hash: "#", search: "?"}
|
var modes = {pathname: "", hash: "#", search: "?"}
|
||||||
var redirect = noop
|
var redirect = noop
|
||||||
var isDefaultRoute = false
|
var isDefaultRoute = false
|
||||||
var routeParams, currentRoute
|
var routeParams, currentRoute, previousRoute
|
||||||
|
|
||||||
m.route = function (root, arg1, arg2, vdom) { // eslint-disable-line
|
m.route = function (root, arg1, arg2, vdom) { // eslint-disable-line
|
||||||
// m.route()
|
// m.route()
|
||||||
|
|
@ -1623,7 +1628,7 @@
|
||||||
}
|
}
|
||||||
// m.route(route, params, shouldReplaceHistoryEntry)
|
// m.route(route, params, shouldReplaceHistoryEntry)
|
||||||
if (isString(root)) {
|
if (isString(root)) {
|
||||||
var oldRoute = currentRoute
|
previousRoute = currentRoute
|
||||||
currentRoute = root
|
currentRoute = root
|
||||||
|
|
||||||
var args = arg1 || {}
|
var args = arg1 || {}
|
||||||
|
|
@ -1659,7 +1664,7 @@
|
||||||
|
|
||||||
var replaceHistory =
|
var replaceHistory =
|
||||||
(arguments.length === 3 ? arg2 : arg1) === true ||
|
(arguments.length === 3 ? arg2 : arg1) === true ||
|
||||||
oldRoute === root
|
previousRoute === root
|
||||||
|
|
||||||
if (global.history.pushState) {
|
if (global.history.pushState) {
|
||||||
var method = replaceHistory ? "replaceState" : "pushState"
|
var method = replaceHistory ? "replaceState" : "pushState"
|
||||||
|
|
@ -1681,6 +1686,8 @@
|
||||||
$location[m.route.mode] = currentRoute
|
$location[m.route.mode] = currentRoute
|
||||||
redirect(modes[m.route.mode] + currentRoute)
|
redirect(modes[m.route.mode] + currentRoute)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
previousRoute = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,7 @@ describe("m.route()", function () {
|
||||||
route("/b")
|
route("/b")
|
||||||
|
|
||||||
expect(spy).to.not.have.been.called
|
expect(spy).to.not.have.been.called
|
||||||
|
expect(m.route()).to.equal("/a")
|
||||||
})
|
})
|
||||||
|
|
||||||
dit("skips route change if subcomponent ctrl.onunload calls preventDefault", function (root) { // eslint-disable-line
|
dit("skips route change if subcomponent ctrl.onunload calls preventDefault", function (root) { // eslint-disable-line
|
||||||
|
|
@ -157,6 +158,7 @@ describe("m.route()", function () {
|
||||||
route("/b")
|
route("/b")
|
||||||
|
|
||||||
expect(spy).to.not.have.been.called
|
expect(spy).to.not.have.been.called
|
||||||
|
expect(m.route()).to.equal("/a")
|
||||||
})
|
})
|
||||||
|
|
||||||
dit("initializes a component's constructor on route change", function (root) { // eslint-disable-line
|
dit("initializes a component's constructor on route change", function (root) { // eslint-disable-line
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue