Skip to content
Permalink
Browse files

fix(router): ensure `history.state` is set in `eager` update mode (#3…

…0154)

Without this change, `history.state` isn't being set when updating the browser URL in `eager` update mode.

PR Close #30154
  • Loading branch information...
jasonaden authored and kara committed Apr 26, 2019
1 parent 132f01c commit 97202278f953d1604484c9eff64cae18945f0500
Showing with 30 additions and 1 deletion.
  1. +2 −1 packages/router/src/router.ts
  2. +28 −0 packages/router/test/integration.spec.ts
@@ -516,7 +516,8 @@ export class Router {
tap(t => {
if (this.urlUpdateStrategy === 'eager') {
if (!t.extras.skipLocationChange) {
this.setBrowserUrl(t.urlAfterRedirects, !!t.extras.replaceUrl, t.id);
this.setBrowserUrl(
t.urlAfterRedirects, !!t.extras.replaceUrl, t.id, t.extras.state);
}
this.browserUrlTree = t.urlAfterRedirects;
}
@@ -631,6 +631,7 @@ describe('Integration', () => {
advance(fixture);
expect(fixture.nativeElement).toHaveText('team 33 [ , right: ]');
})));

it('should eagerly update the URL with urlUpdateStrategy="eagar"',
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
const fixture = TestBed.createComponent(RootCmp);
@@ -722,6 +723,33 @@ describe('Integration', () => {
expect(fixture.nativeElement).toHaveText('team 33 [ , right: ]');
})));

it('should should set `state` with urlUpdateStrategy="eagar"',
fakeAsync(inject([Router, Location], (router: Router, location: SpyLocation) => {

router.urlUpdateStrategy = 'eager';
router.resetConfig([
{path: '', component: SimpleCmp},
{path: 'simple', component: SimpleCmp},
]);

const fixture = createRoot(router, RootCmp);
let navigation: Navigation = null !;
router.events.subscribe(e => {
if (e instanceof NavigationStart) {
navigation = router.getCurrentNavigation() !;
}
});

router.navigateByUrl('/simple', {state: {foo: 'bar'}});
tick();

const history = (location as any)._history;
expect(history[history.length - 1].state.foo).toBe('bar');
expect(history[history.length - 1].state)
.toEqual({foo: 'bar', navigationId: history.length});
expect(navigation.extras.state).toBeDefined();
expect(navigation.extras.state).toEqual({foo: 'bar'});
})));
});

it('should navigate back and forward',

0 comments on commit 9720227

Please sign in to comment.
You can’t perform that action at this time.