From a867754d6a3c2538a8f03f0ff8118d89f8cf344a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yves=20G=C3=A9rardy?= Date: Wed, 5 Jul 2017 23:58:01 +0200 Subject: [PATCH] Don't overwrite the options object when redirecting from onmatch with m.route.set, fix #1857 --- api/router.js | 5 ++++- api/tests/test-router.js | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/api/router.js b/api/router.js index c182008f..93f2e074 100644 --- a/api/router.js +++ b/api/router.js @@ -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) } diff --git a/api/tests/test-router.js b/api/tests/test-router.js index 9406de70..f84019eb 100644 --- a/api/tests/test-router.js +++ b/api/tests/test-router.js @@ -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 }, @@ -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() })