From 8960b2d72189c249baf9d0beadaa8f65aa968949 Mon Sep 17 00:00:00 2001 From: Steven Luscher Date: Sun, 12 Jan 2014 23:23:49 -0800 Subject: [PATCH] Protect against exception when onpopstate/onhashchange are null Without this patch, the following will throw an exception: router = Router(routes) router.configure({ notfound: function() { router.setRoute('/'); } }); router.init(); In the early stages of page load, `window.onpopstate` and `window.onhashchange` are `null` (in Chrome, anyway). --- lib/director/browser.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/director/browser.js b/lib/director/browser.js index 34519f7..e866bc1 100644 --- a/lib/director/browser.js +++ b/lib/director/browser.js @@ -47,7 +47,8 @@ var listener = { fire: function () { if (this.mode === 'modern') { - this.history === true ? window.onpopstate() : window.onhashchange(); + var method = window[this.history === true ? 'onpopstate' : 'onhashchange']; + method && method(); } else { this.onHashChanged();