Skip to content

Commit 2494f0a

Browse files
authored
docs: make external redirects smoother (#32438)
Currently the external redirects use `redirectTo` which ends up flashing the homepage before redirecting users to adev. These changes switch to using a guard which will prevent the flashing since the navigation will never happen.
1 parent ee003d2 commit 2494f0a

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

docs/src/app/routes.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,23 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {Routes} from '@angular/router';
9+
import {Component} from '@angular/core';
10+
import {Route, Routes} from '@angular/router';
1011
import {CanActivateComponentSidenav} from './pages/component-sidenav/component-sidenav-can-load-guard';
1112

12-
function externalRedirect(target: string) {
13-
return () => {
14-
window.location.href = target;
15-
return ''; // unused due to redirect above
13+
@Component({template: ''})
14+
export class RedirectPlaceholder {}
15+
16+
function externalRedirect(target: string): Partial<Route> {
17+
return {
18+
// The router requires a `component`.
19+
component: RedirectPlaceholder,
20+
canActivate: [
21+
() => {
22+
window.location.href = target;
23+
return false;
24+
},
25+
],
1626
};
1727
}
1828

@@ -35,27 +45,27 @@ export const MATERIAL_DOCS_ROUTES: Routes = [
3545
// Component harness, drag & drop docs have moved to angular.dev
3646
{
3747
path: 'cdk/testing',
38-
redirectTo: externalRedirect('https://angular.dev/guide/testing/component-harnesses-overview'),
48+
...externalRedirect('https://angular.dev/guide/testing/component-harnesses-overview'),
3949
},
4050
{
4151
path: 'cdk/testing/api',
42-
redirectTo: externalRedirect('https://angular.dev/api#angular_cdk_testing'),
52+
...externalRedirect('https://angular.dev/api#angular_cdk_testing'),
4353
},
4454
{
4555
path: 'cdk/testing/:tab',
46-
redirectTo: externalRedirect('https://angular.dev/guide/testing/component-harnesses-overview'),
56+
...externalRedirect('https://angular.dev/guide/testing/component-harnesses-overview'),
4757
},
4858
{
4959
path: 'cdk/drag-drop',
50-
redirectTo: externalRedirect('https://angular.dev/guide/drag-drop'),
60+
...externalRedirect('https://angular.dev/guide/drag-drop'),
5161
},
5262
{
5363
path: 'cdk/drag-drop/api',
54-
redirectTo: externalRedirect('https://angular.dev/api#angular_cdk_drag-drop'),
64+
...externalRedirect('https://angular.dev/api#angular_cdk_drag-drop'),
5565
},
5666
{
5767
path: 'cdk/drag-drop/:tab',
58-
redirectTo: externalRedirect('https://angular.dev/guide/drag-drop'),
68+
...externalRedirect('https://angular.dev/guide/drag-drop'),
5969
},
6070
{path: 'guide/system-variables', redirectTo: '/guide/theming-your-components'},
6171
// In v19, the theming system became based on system variables and the mat.theme mixin.

0 commit comments

Comments
 (0)