Skip to content

Commit 28a49f7

Browse files
agundermannmjackson
authored andcommitted
Remove location.path
1 parent ba23ce6 commit 28a49f7

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

modules/History.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,15 @@ class History {
5656
if (typeof this.readState === 'function')
5757
state = this.readState(entry.key);
5858

59-
this.location = this._createLocation(path, state, entry);
59+
this._handleChange(path, state, entry, NavigationTypes.POP, false);
6060
}
6161

6262
handlePop(path, entry = {}) {
6363
var state = null;
6464
if (entry.key && typeof this.readState === 'function')
6565
state = this.readState(entry.key);
6666

67-
this.location = this._createLocation(path, state, entry, NavigationTypes.POP);
68-
this._notifyChange();
67+
this._handleChange(path, state, entry, NavigationTypes.POP);
6968
}
7069

7170
createRandomKey() {
@@ -92,7 +91,7 @@ class History {
9291
var key = this._saveNewState(state);
9392

9493
var entry = null;
95-
if (this.location && this.location.path === path) {
94+
if (this.path === path) {
9695
entry = this.replace(path, key) || {};
9796
} else {
9897
entry = this.push(path, key) || {};
@@ -104,8 +103,7 @@ class History {
104103
this.constructor.name
105104
);
106105

107-
this.location = this._createLocation(path, state, entry, NavigationTypes.PUSH);
108-
this._notifyChange();
106+
this._handleChange(path, state, entry, NavigationTypes.PUSH);
109107
}
110108

111109
replaceState(state, path) {
@@ -119,8 +117,7 @@ class History {
119117
this.constructor.name
120118
);
121119

122-
this.location = this._createLocation(path, state, entry, NavigationTypes.REPLACE);
123-
this._notifyChange();
120+
this._handleChange(path, state, entry, NavigationTypes.REPLACE);
124121
}
125122

126123
back() {
@@ -131,11 +128,19 @@ class History {
131128
this.go(1);
132129
}
133130

131+
_handleChange(path, state, entry, navigationType, notify=true) {
132+
this.path = path;
133+
this.location = this._createLocation(path, state, entry, navigationType);
134+
135+
if (notify)
136+
this._notifyChange();
137+
}
138+
134139
_createLocation(path, state, entry, navigationType) {
135140
var pathname = getPathname(path);
136141
var queryString = getQueryString(path);
137142
var query = queryString ? this.parseQueryString(queryString) : null;
138-
return new Location(path, pathname, query, {...state, ...entry}, navigationType);
143+
return new Location(pathname, query, {...state, ...entry}, navigationType);
139144
}
140145

141146
}

modules/Location.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ class Location {
1212
return object instanceof Location;
1313
}
1414

15-
constructor(path='/', pathname=path, query=null, state=null, navigationType=NavigationTypes.POP) {
16-
this.path = path;
15+
constructor(pathname='/', query=null, state=null, navigationType=NavigationTypes.POP) {
1716
this.pathname = pathname;
1817
this.query = query;
1918
this.state = state;

0 commit comments

Comments
 (0)