1- import { ActivatedRouteSnapshot , Route , Router , RouterStateSnapshot , Routes } from '@angular/router' ;
1+ import {
2+ ActivatedRouteSnapshot ,
3+ Route ,
4+ Router ,
5+ RouterStateSnapshot ,
6+ Routes ,
7+ } from '@angular/router' ;
28import { postRedirects } from './app.routes.map' ;
39import { EMPTY , Subject , catchError , map , tap } from 'rxjs' ;
410import { inject , makeStateKey , TransferState } from '@angular/core' ;
@@ -18,12 +24,16 @@ export const routes: Routes = [
1824 {
1925 path : '' ,
2026 loadComponent : ( ) =>
21- import ( './features/home/home.component' ) . then ( mod => mod . HomeComponent ) ,
27+ import ( './features/home/home.component' ) . then (
28+ mod => mod . HomeComponent
29+ ) ,
2230 } ,
2331 {
2432 path : 'people/:author' ,
2533 loadComponent : ( ) =>
26- import ( './features/author/author.component' ) . then ( m => m . AuthorComponent ) ,
34+ import ( './features/author/author.component' ) . then (
35+ m => m . AuthorComponent
36+ ) ,
2737 } ,
2838 {
2939 path : ':year/:month/:day/:permalink' ,
@@ -92,8 +102,8 @@ export const routes: Routes = [
92102 ) ,
93103 data : { meta : notFoundMeta } ,
94104 } ,
95- ]
96- }
105+ ] ,
106+ } ,
97107] ;
98108
99109function getRouteData ( ) : Partial < Route > {
@@ -106,41 +116,57 @@ function getRouteData(): Partial<Route> {
106116 const transferState = inject ( TransferState ) ;
107117 const stateKey = makeStateKey < PostContent | undefined > ( url ) ;
108118 if ( transferState . hasKey ( stateKey ) ) {
109- const post = transferState . get < PostContent | undefined > ( stateKey , undefined ) ;
119+ const post = transferState . get < PostContent | undefined > (
120+ stateKey ,
121+ undefined
122+ ) ;
110123 postData . next ( post as PostContent ) ;
111124 return post ;
112125 }
113- return inject ( PostsService ) . getPost ( url )
126+ return inject ( PostsService )
127+ . getPost ( url )
114128 . pipe (
115129 tap ( post => {
116130 transferState . set < PostContent > ( stateKey , post ) ;
117- postData . next ( post ) }
118- ) ,
131+ postData . next ( post ) ;
132+ } ) ,
119133 catchError ( ( _ : any ) => {
120134 router . navigate ( [ '**' ] , { skipLocationChange : true } ) ;
121135 return EMPTY ;
122136 } )
123- )
137+ ) ;
124138 } ,
125139 meta : ( activatedRoute : ActivatedRouteSnapshot ) => {
126140 const url = activatedRoute . url . map ( ( { path } ) => path ) . join ( '/' ) ;
127141 const transferState = inject ( TransferState ) ;
128142 const stateKey = makeStateKey < PostContent | undefined > ( url ) ;
129143 if ( transferState . hasKey ( stateKey ) ) {
130- return getPostMeta ( transferState . get < PostContent | undefined > ( stateKey , undefined ) as PostContent , url ) ;
144+ return getPostMeta (
145+ transferState . get < PostContent | undefined > (
146+ stateKey ,
147+ undefined
148+ ) as PostContent ,
149+ url
150+ ) ;
131151 }
132- return postData . pipe ( map ( ( post ) => getPostMeta ( post , url ) ) ) ;
133- }
152+ return postData . pipe ( map ( post => getPostMeta ( post , url ) ) ) ;
153+ } ,
134154 } ,
135155 title : ( activatedRoute : ActivatedRouteSnapshot ) => {
136156 const url = activatedRoute . url . map ( ( { path } ) => path ) . join ( '/' ) ;
137157 const transferState = inject ( TransferState ) ;
138158 const stateKey = makeStateKey < PostContent | undefined > ( url ) ;
139- const getTitle = ( { title } : PostContent ) => `${ title } | ${ activatedRoute . parent ?. title } ` ;
159+ const getTitle = ( { title } : PostContent ) =>
160+ `${ title } | ${ activatedRoute . parent ?. title } ` ;
140161 if ( transferState . hasKey ( stateKey ) ) {
141- return getTitle ( transferState . get < PostContent | undefined > ( stateKey , undefined ) as PostContent ) ;
162+ return getTitle (
163+ transferState . get < PostContent | undefined > (
164+ stateKey ,
165+ undefined
166+ ) as PostContent
167+ ) ;
142168 }
143- return postData . pipe ( map ( ( post ) => getTitle ( post ) ) ) ;
144- }
145- }
169+ return postData . pipe ( map ( post => getTitle ( post ) ) ) ;
170+ } ,
171+ } ;
146172}
0 commit comments