@@ -13,19 +13,6 @@ import {CanActivateComponentSidenav} from './pages/component-sidenav/component-s
1313@Component ( { template : '' } )
1414export class RedirectPlaceholder { }
1515
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- ] ,
26- } ;
27- }
28-
2916export const MATERIAL_DOCS_ROUTES : Routes = [
3017 {
3118 path : '' ,
@@ -45,27 +32,27 @@ export const MATERIAL_DOCS_ROUTES: Routes = [
4532 // Component harness, drag & drop docs have moved to angular.dev
4633 {
4734 path : 'cdk/testing' ,
48- ...externalRedirect ( 'https://angular.dev /guide/testing/component-harnesses-overview') ,
35+ ...adevRedirect ( ' /guide/testing/component-harnesses-overview') ,
4936 } ,
5037 {
5138 path : 'cdk/testing/api' ,
52- ...externalRedirect ( 'https://angular.dev /api#angular_cdk_testing') ,
39+ ...adevRedirect ( ' /api#angular_cdk_testing') ,
5340 } ,
5441 {
5542 path : 'cdk/testing/:tab' ,
56- ...externalRedirect ( 'https://angular.dev /guide/testing/component-harnesses-overview') ,
43+ ...adevRedirect ( ' /guide/testing/component-harnesses-overview') ,
5744 } ,
5845 {
5946 path : 'cdk/drag-drop' ,
60- ...externalRedirect ( 'https://angular.dev /guide/drag-drop') ,
47+ ...adevRedirect ( ' /guide/drag-drop') ,
6148 } ,
6249 {
6350 path : 'cdk/drag-drop/api' ,
64- ...externalRedirect ( 'https://angular.dev /api#angular_cdk_drag-drop') ,
51+ ...adevRedirect ( ' /api#angular_cdk_drag-drop') ,
6552 } ,
6653 {
6754 path : 'cdk/drag-drop/:tab' ,
68- ...externalRedirect ( 'https://angular.dev /guide/drag-drop') ,
55+ ...adevRedirect ( ' /guide/drag-drop') ,
6956 } ,
7057 { path : 'guide/system-variables' , redirectTo : '/guide/theming-your-components' } ,
7158 // In v19, the theming system became based on system variables and the mat.theme mixin.
@@ -92,3 +79,30 @@ export const MATERIAL_DOCS_ROUTES: Routes = [
9279 } ,
9380 { path : '**' , redirectTo : '/404' } ,
9481] ;
82+
83+ function adevRedirect ( path : string ) {
84+ return externalRedirect ( ( ) => {
85+ const match = window . location . hostname . match ( / ^ ( [ a - z A - Z 0 - 9 ] + ) \. m a t e r i a l \. a n g u l a r \. / ) ;
86+ let version : string | null = null ;
87+
88+ if ( match ) {
89+ // adev doesn't have an RC URL so we route to next.
90+ version = match [ 1 ] . toLowerCase ( ) === 'rc' ? 'next' : match [ 1 ] ;
91+ }
92+
93+ return `https://${ version ? version + '.' : '' } angular.dev${ path } ` ;
94+ } ) ;
95+ }
96+
97+ function externalRedirect ( target : string | ( ( ) => string ) ) : Partial < Route > {
98+ return {
99+ // The router requires a `component`.
100+ component : RedirectPlaceholder ,
101+ canActivate : [
102+ ( ) => {
103+ window . location . href = typeof target === 'string' ? target : target ( ) ;
104+ return false ;
105+ } ,
106+ ] ,
107+ } ;
108+ }
0 commit comments