Google web crawler and SEO anguar2

My seo solution in angular2 need little fix. It should be run by resolver – it will help google to handle meta tags. To every route you have to add resolvers, for example:

If you use this solution – google will scan your site in the right way. Without this, sometimes google cannot read proper metatags.

let _resolver = {
    user: UserResolverService,
};
let _resolverMedia = {
    media: VideoResolverService,
}

const appRoutes: Routes = [
    {path: '', component: StatePageIndexComponent, resolve: _resolver},   
    {path: 'video/:slug', component: StatePageMediaSingleComponent, resolve: _resolverMedia},
];

export const appRoutingProviders: any[] = [];

export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);

 

 

@Injectable()
export class VideoResolverService implements Resolve<any> {
    constructor(private seoService: SeoService, private mediaService: VideoService) {
    }
    resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any>|Promise<any>|any {
        return new Observable<Video>(observer => {
            this.videoService.getBySlug(route.params['slug']).subscribe(
                data => {
                    observer.next(data);
                    observer.complete();
                    this.seoService.setVideo(data);
                })

        });

    }
}
  • Thanks for the article.
    You have a typo in title (and URL) 🙂