STEP 1 – I build .Net Core 8.0 Application(API Application)
STEP 2 – I Build Angular 17 SSR Application
STEP 3 – After ng build build command, I copied dist/server and dist/browser folder’s file and pasted to .Net core wwwroot folder
STEP 4 – I have Deployed on Azure App service using publishedSetting option from visualstudio
Now every thing is working except SSR
On app.component.ts I have setup some title and it is working but not working on others pages
Can any body guide me?
here is sample code of demourl component
import { Component, Inject, OnInit, PLATFORM_ID } from '@angular/core';
import { Meta, Title, TransferState } from '@angular/platform-browser';
import { environment } from '../../../../../../environments/environment';
import { isPlatformBrowser, isPlatformServer } from '@angular/common';
@Component({
selector: 'app-demo-url',
standalone: true,
imports: [],
templateUrl: './demo-url.component.html',
styleUrl: './demo-url.component.css',
})
export class DemoUrlComponent implements OnInit {
title: string = '';
constructor(
@Inject(PLATFORM_ID) private platformId: Object,
private transferState: TransferState,
private titleService: Title,
private metaService: Meta
) {}
ngOnInit() {
if (isPlatformServer(this.platformId)) {
console.log('Server call 123');
this.titleService.setTitle(`Server - My Demo Title`);
this.metaService.addTag({
name: 'Description',
content: 'This is a test job description',
});
this.metaService.addTag({
name: 'keywords',
content: 'Angular, Universal, TransferState, MetaService',
});
this.metaService.addTag({
property: 'og:title',
content: 'My Demo Title',
});
this.metaService.addTag({
property: 'og:description',
content: 'This is a test job description',
});
this.metaService.addTag({
property: 'og:image',
content:
'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png',
});
this.metaService.addTag({
property: 'og:image:height',
content: '1200',
});
this.metaService.addTag({
property: 'og:image:width',
content: '1200',
});
this.metaService.addTag({
property: 'og:type',
content: 'website',
});
} else if (isPlatformBrowser(this.platformId)) {
this.titleService.setTitle(`Browser - My Demo Title`);
this.metaService.addTag({
name: 'Description',
content: 'This is a test job description',
});
this.metaService.addTag({
name: 'keywords',
content: 'Angular, Universal, TransferState, MetaService',
});
this.metaService.addTag({
property: 'og:title',
content: 'My Demo Title',
});
this.metaService.addTag({
property: 'og:description',
content: 'This is a test job description',
});
this.metaService.addTag({
property: 'og:image',
content:
'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png',
});
this.metaService.addTag({
property: 'og:image:height',
content: '1200',
});
this.metaService.addTag({
property: 'og:image:width',
content: '1200',
});
this.metaService.addTag({
property: 'og:type',
content: 'website',
});
}
}
}
title set up for other pages should also be displayed on page view source file for SEO purpose
Dimpal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
9