From 681bb4a39ac0ad8d5ddebce3a009aaa7b49da223 Mon Sep 17 00:00:00 2001 From: "Yoshua Wuyts [taking a vacation, back 31/07]" Date: Tue, 1 Aug 2017 02:08:12 +0200 Subject: [PATCH] don't rerender before load (#541) --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7d14e30..eb385f5 100644 --- a/index.js +++ b/index.js @@ -39,6 +39,7 @@ function Choo (opts) { this._hrefEnabled = opts.href === undefined ? true : opts.href this._hasWindow = typeof window !== 'undefined' this._createLocation = nanolocation + this._loaded = false this._tree = null // properties that are part of the API @@ -87,9 +88,11 @@ Choo.prototype.start = function () { var self = this if (this._historyEnabled) { this.emitter.prependListener(this._events.NAVIGATE, function () { - self.emitter.emit(self._events.RENDER) self.state.query = nanoquery(window.location.search) - setTimeout(scrollToAnchor.bind(null, window.location.hash), 0) + if (self._loaded) { + self.emitter.emit(self._events.RENDER) + setTimeout(scrollToAnchor.bind(null, window.location.hash), 0) + } }) this.emitter.prependListener(this._events.POPSTATE, function () { @@ -147,6 +150,7 @@ Choo.prototype.start = function () { documentReady(function () { self.emitter.emit(self._events.DOMCONTENTLOADED) + self._loaded = true }) return this._tree