don't duplicate route args when redirecting #352
This commit is contained in:
parent
83bc89f188
commit
6ef1f8ae2e
2 changed files with 37 additions and 8 deletions
19
mithril.js
19
mithril.js
|
|
@ -1,4 +1,4 @@
|
||||||
Mithril = m = new function app(window, undefined) {
|
var m = (function app(window, undefined) {
|
||||||
var OBJECT = "[object Object]", ARRAY = "[object Array]", STRING = "[object String]", FUNCTION = "function";
|
var OBJECT = "[object Object]", ARRAY = "[object Array]", STRING = "[object String]", FUNCTION = "function";
|
||||||
var type = {}.toString;
|
var type = {}.toString;
|
||||||
var parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g, attrParser = /\[(.+?)(?:=("|'|)(.*?)\2)?\]/;
|
var parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g, attrParser = /\[(.+?)(?:=("|'|)(.*?)\2)?\]/;
|
||||||
|
|
@ -581,11 +581,16 @@ Mithril = m = new function app(window, undefined) {
|
||||||
element.removeEventListener("click", routeUnobtrusive);
|
element.removeEventListener("click", routeUnobtrusive);
|
||||||
element.addEventListener("click", routeUnobtrusive)
|
element.addEventListener("click", routeUnobtrusive)
|
||||||
}
|
}
|
||||||
//m.route(route)
|
//m.route(route, params)
|
||||||
else if (type.call(arguments[0]) == STRING) {
|
else if (type.call(arguments[0]) == STRING) {
|
||||||
currentRoute = arguments[0];
|
currentRoute = arguments[0];
|
||||||
var querystring = arguments[1] != null && type.call(arguments[1]) == OBJECT ? buildQueryString(arguments[1]) : null;
|
var args = arguments[1] || {}
|
||||||
if (querystring) currentRoute += (currentRoute.indexOf("?") === -1 ? "?" : "&") + querystring;
|
var queryIndex = currentRoute.indexOf("?")
|
||||||
|
var params = queryIndex > -1 ? parseQueryString(currentRoute.slice(queryIndex + 1)) : {}
|
||||||
|
for (var i in args) params[i] = args[i]
|
||||||
|
var querystring = buildQueryString(params)
|
||||||
|
var currentPath = queryIndex > -1 ? currentRoute.slice(0, queryIndex) : currentRoute
|
||||||
|
if (querystring) currentRoute = currentPath + (currentPath.indexOf("?") === -1 ? "?" : "&") + querystring;
|
||||||
|
|
||||||
var shouldReplaceHistoryEntry = (arguments.length == 3 ? arguments[2] : arguments[1]) === true;
|
var shouldReplaceHistoryEntry = (arguments.length == 3 ? arguments[2] : arguments[1]) === true;
|
||||||
|
|
||||||
|
|
@ -655,7 +660,7 @@ Mithril = m = new function app(window, undefined) {
|
||||||
var pairs = str.split("&"), params = {};
|
var pairs = str.split("&"), params = {};
|
||||||
for (var i = 0; i < pairs.length; i++) {
|
for (var i = 0; i < pairs.length; i++) {
|
||||||
var pair = pairs[i].split("=");
|
var pair = pairs[i].split("=");
|
||||||
params[decodeSpace(pair[0])] = pair[1] ? decodeSpace(pair[1]) : (pair.length === 1 ? true : "")
|
params[decodeSpace(pair[0])] = pair[1] ? decodeSpace(pair[1]) : ""
|
||||||
}
|
}
|
||||||
return params
|
return params
|
||||||
}
|
}
|
||||||
|
|
@ -972,7 +977,7 @@ Mithril = m = new function app(window, undefined) {
|
||||||
m.deps.factory = app;
|
m.deps.factory = app;
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}(typeof window != "undefined" ? window : {});
|
})(typeof window != "undefined" ? window : {});
|
||||||
|
|
||||||
if (typeof module != "undefined" && module !== null && module.exports) module.exports = m;
|
if (typeof module != "undefined" && module !== null && module.exports) module.exports = m;
|
||||||
if (typeof define == "function" && define.amd) define(function() {return m});
|
else if (typeof define == "function" && define.amd) define(function() {return m});
|
||||||
|
|
|
||||||
|
|
@ -1063,7 +1063,7 @@ function testMithril(mock) {
|
||||||
mock.requestAnimationFrame.$resolve()
|
mock.requestAnimationFrame.$resolve()
|
||||||
m.route("/test14?test&test2=")
|
m.route("/test14?test&test2=")
|
||||||
mock.requestAnimationFrame.$resolve() //teardown
|
mock.requestAnimationFrame.$resolve() //teardown
|
||||||
return mock.location.search == "?/test14?test&test2=" && m.route.param("test") === true && m.route.param("test2") === ""
|
return mock.location.search == "?/test14?test=&test2=" && m.route.param("test") === "" && m.route.param("test2") === ""
|
||||||
})
|
})
|
||||||
test(function() {
|
test(function() {
|
||||||
mock.requestAnimationFrame.$resolve() //setup
|
mock.requestAnimationFrame.$resolve() //setup
|
||||||
|
|
@ -1597,6 +1597,30 @@ function testMithril(mock) {
|
||||||
|
|
||||||
return root.childNodes[0].nodeValue == "b"
|
return root.childNodes[0].nodeValue == "b"
|
||||||
})
|
})
|
||||||
|
test(function() {
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
mock.location.search = "?"
|
||||||
|
|
||||||
|
var root = mock.document.createElement("div")
|
||||||
|
|
||||||
|
var a = {}
|
||||||
|
a.controller = function() {
|
||||||
|
m.route("/b?foo=1", {foo: 2})
|
||||||
|
}
|
||||||
|
a.view = function() {return "a"}
|
||||||
|
|
||||||
|
var b = {}
|
||||||
|
b.controller = function() {}
|
||||||
|
b.view = function() {return "b"}
|
||||||
|
|
||||||
|
m.route(root, "/", {
|
||||||
|
"/": a,
|
||||||
|
"/b": b,
|
||||||
|
})
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
||||||
|
return mock.location.search == "?/b?foo=2"
|
||||||
|
})
|
||||||
//end m.route
|
//end m.route
|
||||||
|
|
||||||
//m.prop
|
//m.prop
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue