Skip to content
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class Router extends Component {
this.state = {
url: props.url || getCurrentUrl()
};

initEventListeners();
}

Expand Down Expand Up @@ -179,7 +179,12 @@ class Router extends Component {
}

componentWillMount() {
ROUTERS.push(this);
// preact-render-to-string initializes components with the dirty flag set.
Comment thread
developit marked this conversation as resolved.
Outdated
// We can use this to detect a static rendering environment and disable subscriptions.
this._ssr = '_nextState' in this || '__s' in this;
Comment thread
developit marked this conversation as resolved.
Outdated
if (!this._ssr) {
ROUTERS.push(this);
}
this.updating = true;
}

Expand All @@ -194,7 +199,7 @@ class Router extends Component {

componentWillUnmount() {
if (typeof this.unlisten==='function') this.unlisten();
ROUTERS.splice(ROUTERS.indexOf(this), 1);
ROUTERS.splice(ROUTERS.indexOf(this) >>> 0, 1);
}

componentWillUpdate() {
Expand Down Expand Up @@ -230,7 +235,7 @@ class Router extends Component {
let current = active[0] || null;

let previous = this.previousUrl;
if (url!==previous) {
if (!this._ssr && url!==previous) {
this.previousUrl = url;
if (typeof onChange==='function') {
onChange({
Expand Down