简体   繁体   English

Angular.js和SEO

[英]Angular.js and SEO

I'd like to create a site with Angular (I'm new), but also want to be able to have different "views" be cachable in the search engines and have their own URL routes. 我想用Angular创建一个网站(我是新手),但也希望能够在搜索引擎中拥有不同的“视图”,并拥有自己的URL路由。 How would I achieve this with Angular, or is best not to use it? 我将如何使用Angular做到这一点,或者最好不要使用它?

Enable pushState in Angular with $locationProvider.html5Mode(true); 使用$locationProvider.html5Mode(true);在Angular中启用pushState $locationProvider.html5Mode(true); so that you have real URLs and make sure that, when the URL is requested by the client, you deliver the complete page for that URL from the server (and not a set of empty templates that you populate with JS). 因此您拥有真实的URL,并确保在客户端请求该URL时,从服务器交付该URL的完整页面(而不是使用JS填充的一组空模板)。

When a link is followed, you'll go through an Angular view and update the existing DOM (while changing the URL with pushState ) but the initial load should be a complete page. 跟随链接时,您将进入Angular视图并更新现有DOM(同时使用pushState更改URL),但初始加载应为完整页面。

This does mean duplicating effort (you need client and server side versions of the code for building each page). 这确实意味着要进行重复的工作(您需要使用客户端和服务器端版本的代码来构建每个页面)。 Isomorphic JS is popular for dealing with that issue. 同构JS非常适合处理该问题。

If you want to expose Angular views to search engines and other bots, I suggest using an open source framework that we developed at Say Media. 如果要将Angular视图公开给搜索引擎和其他漫游器,建议您使用我们在Say Media开发的开源框架。 It uses node.js to render the pages on the server when it detects a bot vs a real user. 当它检测到机器人与真实用户时,它使用node.js在服务器上呈现页面。 You can find it here: 你可以在这里找到它:

https://github.com/saymedia/angularjs-server https://github.com/saymedia/angularjs-server

I would suggest not using different routes, however, as most search engines will penalize you for having duplicate content on multiple urls. 但我建议您不要使用其他路由,因为大多数搜索引擎会因在多个网址上重复内容而对您不利。 And while you might think they would just hit the bot version of your site, they are getting more sophisticated about crawling single page app like sites. 尽管您可能认为他们只是会打上您网站的漫游器版本,但它们在抓取类似网站的单页面应用程序方面变得越来越复杂。 I would be cautious about duplicate routes for the same content. 对于相同内容的重复路线,我会保持谨慎。

Good Luck! 祝好运!

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

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