Skip to content

Commit 132f01c

Browse files
jasonadenkara
authored andcommittedMay 6, 2019
fix(router): fix a problem with router not responding to back button (#30160)
There was a problem with a combination of the `eager` URL update, browser `back` button, and hybrid applications. Details provided in internal ticket http://b/123667227. This fix handles the problem by setting `router.browserUrlTree` when all conditions have failed, meaning the browser doesn't do anything with the navigation other than update internal data structures. Without this change, the problem was an old value was stored in `router.broserUrlTree` causing some new navigations to be compared to an old value and breaking future navigations. PR Close #30160
1 parent 6a987f1 commit 132f01c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
 

‎packages/router/src/router.ts

+1
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ export class Router {
555555
* way the next navigation will be coming from the current URL in the browser.
556556
*/
557557
this.rawUrlTree = t.rawUrl;
558+
this.browserUrlTree = t.urlAfterRedirects;
558559
t.resolve(null);
559560
return EMPTY;
560561
}

‎packages/router/test/integration.spec.ts

+27
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,33 @@ describe('Integration', () => {
661661
expect(location.path()).toEqual('/login');
662662
})));
663663

664+
it('should set browserUrlTree with urlUpdateStrategy="eagar" and false `shouldProcessUrl`',
665+
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
666+
const fixture = TestBed.createComponent(RootCmp);
667+
advance(fixture);
668+
669+
router.urlUpdateStrategy = 'eager';
670+
671+
router.resetConfig([
672+
{path: 'team/:id', component: SimpleCmp},
673+
{path: 'login', component: AbsoluteSimpleLinkCmp}
674+
]);
675+
676+
router.navigateByUrl('/team/22');
677+
advance(fixture, 1);
678+
679+
expect((router as any).browserUrlTree.toString()).toBe('/team/22');
680+
681+
// Force to not process URL changes
682+
router.urlHandlingStrategy.shouldProcessUrl = (url: UrlTree) => false;
683+
684+
router.navigateByUrl('/login');
685+
advance(fixture, 1);
686+
687+
// Because we now can't process any URL, we will end up back at the root.
688+
expect((router as any).browserUrlTree.toString()).toBe('/');
689+
})));
690+
664691
it('should eagerly update URL after redirects are applied with urlUpdateStrategy="eagar"',
665692
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
666693
const fixture = TestBed.createComponent(RootCmp);

0 commit comments

Comments
 (0)