[英]Angular2 SEO tags and prerendering
I have created Angular2 (Angular 4.4.3) app with dynamic content loaded over API. 我创建了Angular2(Angular 4.4.3)应用,并通过API加载了动态内容。
I have used official docs for setting title and meta (Added in v4): https://angular.io/guide/set-document-title https://angular.io/api/platform-browser/Meta 我已经使用官方文档来设置标题和元(在v4中添加): https : //angular.io/guide/set-document-title https://angular.io/api/platform-browser/Meta
And I have used this guide to create prerender server: https://blog.pusher.com/make-angular-4-app-seo-friendly/ (skip to: Creating an Express server to make your Angular app SEO friendly) 而且我已经使用该指南来创建预渲染服务器: https : //blog.pusher.com/make-angular-4-app-seo-friendly/ (跳至:创建Express服务器以使您的Angular应用SEO友好)
But it's not working as described. 但是它没有按照描述的那样工作。 For example, in AppComponent.ts
例如,在AppComponent.ts中
export class AppComponent implements AfterViewInit {
constructor(public router: Router,
private activatedRoute: ActivatedRoute,
private titleService: Title) {
this.titleService.setTitle("SOME CUSTOM TITLE");
}
And when I open page, I see that set as Title in browser, but when opening source of page, I see this: 当我打开页面时,我在浏览器中看到设置为标题,但是当打开页面源时,我看到了:
I have also used regular build, and AOT build but same thing, here's conf: tsconfig-aot.json:
我也使用了常规构建和AOT构建,但是相同的是conf:tsconfig-aot.json:
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es2015", "dom"],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"typeRoots": [
"./node_modules/@types/"
]
},
"files": [
"src/app/app.module.ts",
"src/main.ts"
],
"angularCompilerOptions": {
"genDir": "aot",
"skipMetadataEmit" : true
}
}
tsconfig.app.json
{
"extends": "../tsconfig-aot.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "es2015",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
How can I set meta title / description from AppComponent or if possible from some other child component so it can be visible in source code, or when google crawls site? 如何从AppComponent或如果可能的话从其他子组件设置元标题/描述,以便在源代码中可见,或者在Google抓取网站时可见?
Actually a problem was serving content from server. 实际上,问题在于从服务器提供内容。 I have tried to serve content directly with Nginx, but thing is that node should run server pack first, and then connect with Nginx as proxy only.
我曾尝试直接通过Nginx提供内容,但问题是该节点应首先运行服务器包,然后仅与Nginx作为代理连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.