fix(docs-infra): fix redirect in angular version selector (#35632)
Closes #35630 PR Close #35632
This commit is contained in:
parent
73ee57a6e3
commit
de4e17b76e
|
@ -417,6 +417,15 @@ describe('AppComponent', () => {
|
||||||
selectElement.triggerEventHandler('change', { option: versionWithoutUrl, index: versionWithoutUrlIndex });
|
selectElement.triggerEventHandler('change', { option: versionWithoutUrl, index: versionWithoutUrlIndex });
|
||||||
expect(locationService.go).not.toHaveBeenCalled();
|
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', () => {
|
describe('currentDocument', () => {
|
||||||
|
|
|
@ -149,8 +149,8 @@ export class AppComponent implements OnInit {
|
||||||
]).subscribe(([versionInfo, versions]) => {
|
]).subscribe(([versionInfo, versions]) => {
|
||||||
// TODO(pbd): consider whether we can lookup the stable and next versions from the internet
|
// TODO(pbd): consider whether we can lookup the stable and next versions from the internet
|
||||||
const computedVersions: NavigationNode[] = [
|
const computedVersions: NavigationNode[] = [
|
||||||
{ title: 'next', url: 'https://next.angular.io' },
|
{ title: 'next', url: 'https://next.angular.io/' },
|
||||||
{ title: 'stable', url: 'https://angular.io' },
|
{ title: 'stable', url: 'https://angular.io/' },
|
||||||
];
|
];
|
||||||
if (this.deployment.mode === 'archive') {
|
if (this.deployment.mode === 'archive') {
|
||||||
computedVersions.push({ title: `v${versionInfo.major}` });
|
computedVersions.push({ title: `v${versionInfo.major}` });
|
||||||
|
@ -232,7 +232,8 @@ export class AppComponent implements OnInit {
|
||||||
onDocVersionChange(versionIndex: number) {
|
onDocVersionChange(versionIndex: number) {
|
||||||
const version = this.docVersions[versionIndex];
|
const version = this.docVersions[versionIndex];
|
||||||
if (version.url) {
|
if (version.url) {
|
||||||
this.locationService.go(`${version.url}${this.currentUrl}`);
|
const versionUrl = version.url + (!version.url.endsWith('/') ? '/' : '');
|
||||||
|
this.locationService.go(`${versionUrl}${this.currentUrl}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue