Skip to content

Commit

Permalink
Don't overwrite the options object when redirecting from onmatch with…
Browse files Browse the repository at this point in the history
… m.route.set, fix MithrilJS#1857
  • Loading branch information
pygy committed Jul 5, 2017
1 parent 9b947f4 commit a867754
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion api/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ module.exports = function($window, redrawService) {
redrawService.subscribe(root, run)
}
route.set = function(path, data, options) {
if (lastUpdate != null) options = {replace: true}
if (lastUpdate != null) {
options = options || {}
options.replace = true
}
lastUpdate = null
routeService.setPath(path, data, options)
}
Expand Down
3 changes: 2 additions & 1 deletion api/tests/test-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ o.spec("route", function() {
route(root, "/a", {
"/a" : {
onmatch: function() {
route.set("/b")
route.set("/b", {}, {state: {a: 5}})
},
render: render
},
Expand All @@ -684,6 +684,7 @@ o.spec("route", function() {
o(view.callCount).equals(1)
o(root.childNodes.length).equals(1)
o(root.firstChild.nodeName).equals("DIV")
o($window.history.state).deepEquals({a: 5})

done()
})
Expand Down

0 comments on commit a867754

Please sign in to comment.