Routing NG: persist state on partial updates (#33687)

* Persist location state on partial updates

* Add test
This commit is contained in:
Dominik Prokop 2021-05-06 09:15:52 +02:00 committed by GitHub
parent a5ae8cf377
commit ca54b4d6b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -35,5 +35,20 @@ describe('LocationService', () => {
expect(locationService.getLocation().search).toBe('?servers=A&servers=B&servers=C');
});
it('persist state', () => {
locationService.push({
pathname: '/d/123',
state: {
some: 'stateToPersist',
},
});
locationService.partial({ q: 1 });
expect(locationService.getLocation().search).toBe('?q=1');
expect(locationService.getLocation().state).toEqual({
some: 'stateToPersist',
});
});
});
});

View File

@ -67,9 +67,9 @@ export class HistoryWrapper implements LocationService {
const updatedUrl = urlUtil.renderUrl(currentLocation.pathname, newQuery);
if (replace) {
this.history.replace(updatedUrl);
this.history.replace(updatedUrl, this.history.location.state);
} else {
this.history.push(updatedUrl);
this.history.push(updatedUrl, this.history.location.state);
}
}