Skip to content

Commit

Permalink
fixup! feat(router): add hash-based navigation option to setUpLocatio…
Browse files Browse the repository at this point in the history
…nSync
  • Loading branch information
jasonaden committed Feb 13, 2019
1 parent fa1db49 commit 515ae50
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/router/upgrade/src/upgrade.ts
Expand Up @@ -75,8 +75,9 @@ export function setUpLocationSync(ngUpgrade: UpgradeModule, urlType: 'path' | 'h
if (urlType === 'path') { if (urlType === 'path') {
url = resolveUrl(next); url = resolveUrl(next);
} else if (urlType === 'hash') { } else if (urlType === 'hash') {
// Remove the leading hash from the URL // Remove the first hash from the URL
url = resolveUrl(next.substring(1)); const hashIdx = next.indexOf('#');
url = resolveUrl(next.substring(0, hashIdx) + next.substring(hashIdx + 1));
} else { } else {
throw 'Invalid URLType passed to setUpLocationSync: ' + urlType; throw 'Invalid URLType passed to setUpLocationSync: ' + urlType;
} }
Expand Down
2 changes: 1 addition & 1 deletion packages/router/upgrade/test/upgrade.spec.ts
Expand Up @@ -97,7 +97,7 @@ describe('setUpLocationSync', () => {
callback({}, combinedUrl, ''); callback({}, combinedUrl, '');


expect(LocationMock.normalize).toHaveBeenCalledTimes(1); expect(LocationMock.normalize).toHaveBeenCalledTimes(1);
expect(LocationMock.normalize).toHaveBeenCalledWith(pathname + query + hash); expect(LocationMock.normalize).toHaveBeenCalledWith(pathname);


expect(RouterMock.navigateByUrl).toHaveBeenCalledTimes(1); expect(RouterMock.navigateByUrl).toHaveBeenCalledTimes(1);
expect(RouterMock.navigateByUrl).toHaveBeenCalledWith(normalizedPathname + query + hash); expect(RouterMock.navigateByUrl).toHaveBeenCalledWith(normalizedPathname + query + hash);
Expand Down

0 comments on commit 515ae50

Please sign in to comment.