fix(docs-infra): fix redirect in angular version selector (#35632)

Closes #35630

PR Close #35632
This commit is contained in:
Sonu Kapoor 2020-02-22 17:18:01 -05:00 committed by atscott
parent 73ee57a6e3
commit de4e17b76e
2 changed files with 13 additions and 3 deletions

View File

@ -417,6 +417,15 @@ describe('AppComponent', () => {
selectElement.triggerEventHandler('change', { option: versionWithoutUrl, index: versionWithoutUrlIndex });
expect(locationService.go).not.toHaveBeenCalled();
});
it('should navigate when change to a version with a url that does not end with `/`', async () => {
await setupSelectorForTesting();
locationService.urlSubject.next('docs#section-1');
const versionWithoutSlashIndex = component.docVersions.length;
const versionWithoutSlashUrl = component.docVersions[versionWithoutSlashIndex] = { url: 'https://next.angular.io', title: 'foo' };
selectElement.triggerEventHandler('change', { option: versionWithoutSlashUrl, index: versionWithoutSlashIndex });
expect(locationService.go).toHaveBeenCalledWith('https://next.angular.io/docs#section-1');
});
});
describe('currentDocument', () => {

View File

@ -149,8 +149,8 @@ export class AppComponent implements OnInit {
]).subscribe(([versionInfo, versions]) => {
// TODO(pbd): consider whether we can lookup the stable and next versions from the internet
const computedVersions: NavigationNode[] = [
{ title: 'next', url: 'https://next.angular.io' },
{ title: 'stable', url: 'https://angular.io' },
{ title: 'next', url: 'https://next.angular.io/' },
{ title: 'stable', url: 'https://angular.io/' },
];
if (this.deployment.mode === 'archive') {
computedVersions.push({ title: `v${versionInfo.major}` });
@ -232,7 +232,8 @@ export class AppComponent implements OnInit {
onDocVersionChange(versionIndex: number) {
const version = this.docVersions[versionIndex];
if (version.url) {
this.locationService.go(`${version.url}${this.currentUrl}`);
const versionUrl = version.url + (!version.url.endsWith('/') ? '/' : '');
this.locationService.go(`${versionUrl}${this.currentUrl}`);
}
}