简体   繁体   English

预渲染Angular 6(用于SEO)不会将routerLink转换为Href

[英]Prerendering Angular 6 (for SEO) does not translate routerLink to Href

I am using prerender.io to render angular 6 pages using headless chrome. 我正在使用prerender.io使用无头的chrome渲染角度6页。 The problem is that the renderer does not render the router links and the link information gets lost. 问题是渲染器不渲染路由器链接,并且链接信息丢失。

This is especially problematic, given that the purpose of rendering is SEO. 鉴于渲染的目的是SEO,因此这尤其成问题。

For example, a button with [routerLink]="previewLink", will be rendered to a button with no router link. 例如,带有[routerLink] =“ previewLink”的按钮将呈现为没有路由器链接的按钮。

Here is a live example 这是一个真实的例子

rendered page with no links 没有链接的渲染页面

https://prerender.io/raw-html?url=https%3A%2F%2Fwww.fiveabook.com%2Fbooks&adaptiveType=desktop https://prerender.io/raw-html?url=https%3A%2F%2Fwww.fiveabook.com%2Fbooks&adaptiveType=desktop

No href and no router link in the "Preview" buttons: “预览”按钮中没有href和路由器链接:

<button _ngcontent-c12="" color="accent" mat-button="" tabindex="0" class="mat-button mat-accent ng-star-inserted"><span class="mat-button-wrapper">

angular page with router links 带路由器链接的角度页面

https://www.fiveabook.com/books https://www.fiveabook.com/books

The buttons have dynamically generated router links. 这些按钮具有动态生成的路由器链接。

  • Initiallly, the question was in regards to href links. 最初,问题是关于href链接的。 However, the buttons don't have href links. 但是,这些按钮没有href链接。 Nevertheless, the rendered does not render the router links in the Preview buttons so I am not sure if googlebot can see where the buttons link to. 不过,渲染后的渲染按钮不会渲染“预览”按钮中的路由器链接,因此我不确定googlebot是否可以看到按钮链接到的位置。

If I load https://www.fiveabook.com/books directly in my Chrome browser on my Mac and look for that button, I'm not seeing an href there either: 如果我直接在Mac上的Chrome浏览器中加载https://www.fiveabook.com/books并查找该按钮,那么我也看不到href:

在此处输入图片说明

So it looks like we are rendering the page exactly as a normal Chrome browser is rendering it. 因此,看起来我们所呈现的页面与普通Chrome浏览器所呈现的完全相同。

Html buttons dont have a href attribute. HTML按钮没有href属性。 Simply use an anchor element if you want to generate a hyperlink button. 如果要生成超链接按钮,只需使用锚元素

<a mat-button [routerLink]="...">
Link
</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM