Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions aio/src/app/app.component.spec.ts
Expand Up @@ -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', () => {
Expand Down
7 changes: 4 additions & 3 deletions aio/src/app/app.component.ts
Expand Up @@ -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}` });
Expand Down Expand Up @@ -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('/') ? '/' : '');
sonukapoor marked this conversation as resolved.
Show resolved Hide resolved
this.locationService.go(`${versionUrl}${this.currentUrl}`);
}
}

Expand Down