diff --git a/modules/@angular/router/src/url_tree.ts b/modules/@angular/router/src/url_tree.ts index 175d96c756..fef13c0412 100644 --- a/modules/@angular/router/src/url_tree.ts +++ b/modules/@angular/router/src/url_tree.ts @@ -294,7 +294,7 @@ class UrlParser { this.capture('/'); } - if (this.remaining === '' || this.remaining.startsWith('?')) { + if (this.remaining === '' || this.remaining.startsWith('?') || this.remaining.startsWith('#')) { return new UrlSegment([], {}); } else { return new UrlSegment([], this.parseSegmentChildren()); diff --git a/modules/@angular/router/test/router.spec.ts b/modules/@angular/router/test/router.spec.ts index d6b632ee81..948b65cb1b 100644 --- a/modules/@angular/router/test/router.spec.ts +++ b/modules/@angular/router/test/router.spec.ts @@ -1226,35 +1226,34 @@ describe('Integration', () => { it('should set the class on a parent element when the link is active', - fakeAsync(inject( - [Router, TestComponentBuilder, Location], - (router: Router, tcb: TestComponentBuilder, location: Location) => { - const fixture = createRoot(tcb, router, RootCmp); + fakeAsync(inject( + [Router, TestComponentBuilder, Location], + (router: Router, tcb: TestComponentBuilder, location: Location) => { + const fixture = createRoot(tcb, router, RootCmp); - router.resetConfig([{ - path: 'team/:id', - component: TeamCmp, - children: [{ - path: 'link', - component: DummyLinkWithParentCmp, - children: [ - {path: 'simple', component: SimpleCmp}, {path: '', component: BlankCmp} - ] - }] - }]); + router.resetConfig([{ + path: 'team/:id', + component: TeamCmp, + children: [{ + path: 'link', + component: DummyLinkWithParentCmp, + children: + [{path: 'simple', component: SimpleCmp}, {path: '', component: BlankCmp}] + }] + }]); - router.navigateByUrl('/team/22/link;exact=true'); - advance(fixture); - expect(location.path()).toEqual('/team/22/link;exact=true'); + router.navigateByUrl('/team/22/link;exact=true'); + advance(fixture); + expect(location.path()).toEqual('/team/22/link;exact=true'); - const native = fixture.debugElement.nativeElement.querySelector('link-parent'); - expect(native.className).toEqual('active'); + const native = fixture.debugElement.nativeElement.querySelector('link-parent'); + expect(native.className).toEqual('active'); - router.navigateByUrl('/team/22/link/simple'); - advance(fixture); - expect(location.path()).toEqual('/team/22/link/simple'); - expect(native.className).toEqual(''); - }))); + router.navigateByUrl('/team/22/link/simple'); + advance(fixture); + expect(location.path()).toEqual('/team/22/link/simple'); + expect(native.className).toEqual(''); + }))); it('should set the class when the link is active', fakeAsync(inject( diff --git a/modules/@angular/router/test/url_serializer.spec.ts b/modules/@angular/router/test/url_serializer.spec.ts index 3fc810b209..2204c3e7d9 100644 --- a/modules/@angular/router/test/url_serializer.spec.ts +++ b/modules/@angular/router/test/url_serializer.spec.ts @@ -156,6 +156,11 @@ describe('url serializer', () => { expect(url.serialize(tree)).toEqual('/one#two'); }); + it('should parse fragment (root)', () => { + const tree = url.parse('/#one'); + expectSegment(tree.root, ''); + expect(url.serialize(tree)).toEqual('/#one'); + }); it('should parse empty fragment', () => { const tree = url.parse('/one#');