<a [routerLink]="['/article', row.slug ]" [state]="{ hello: 'world' }" class="preview-link">
<span>{{row.slug }}</span>
</a>
我的解析器
import { Injectable, } from '@angular/core'; import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot, ActivatedRoute, NavigationStart } from '@angular/router'; import { Observable } from 'rxjs'; import { catchError } from 'rxjs/operators'; import { Article } from '../../entities'; import { UserService } from './../../../../shared/shared-services/core'; import { ArticlesService } from '../../services'; import { filter, map } from 'rxjs/operators'; @Injectable() export class ArticleResolver implements Resolve<Article> { constructor( private articlesService: ArticlesService, private router: Router, private userService: UserService ) {} resolve( route: ActivatedRouteSnapshot, state: RouterStateSnapshot ): Observable<any> { // state printed successfully here console.log(this.router.getCurrentNavigation().extras.state); return this.articlesService.get(route.params['slug']) .pipe(catchError((err) => this.router.navigateByUrl('/'))); } }
我的组件
constructor(
private route: ActivatedRoute,
private articlesService: ArticlesService,
private commentsService: CommentsService,
private router: Router,
private userService: UserService,
public deviceService: DeviceDetectorService
) { }
ngOnInit() {
// Retreive the prefetched article
this.route.data.subscribe(
(data: { article: Article }) => {
this.article = data.article;
// Here i trying to display state but it's print undefined
console.log(this.router.getCurrentNavigation().extras.state);
}
);
在获取所需数据之后,将动态状态[state] =“ {hello:'world'}”传递到解析器,然后传递到组件,在解析器中显示的状态,但是无法在我的组件中显示状态,因为它是...