SEO:如何从客户端api请求中索引数据

时间:2018-07-24 19:15:37

标签: javascript angular typescript seo angular-universal

我不是在寻找有关如何进行此设置的特定教程。我实际上是想知道什么是可能的,什么是不可能的。

在Angular 6应用程序中,我正在学习如何在服务器端加载内容,以便漫游器可以索引客户端数据。我也想对来自api请求的很多数据进行爬网。例如,以下代码从我的电子商务API中获取当前页面项目数据。

在我的角度组件中

getProductById(product_id) {
    const data = { product_id: product_id };
    return this.http.get<any>( api_url + '/getProductById', {params: data} );
}

这是对我的api的调用,该API从BigCommerce返回数据(见下文)

我的Express API

getProductById = (req, res, next) => {
    let product_id = req.query.product_id;
    return bc_v3.get(`/catalog/products/${product_id}`).then(data => {
        return data; // this data will then return back to the client async
    });
};

是否可以索引来自API的数据?

SEO机器人能否将API返回的数据编入索引?

2 个答案:

答案 0 :(得分:2)

如果您使用服务器端预渲染并将数据注入到html中,我相信可以。这里有一个使用.Net Core来执行此操作的示例:https://github.com/MarkPieszak/aspnetcore-angular2-universal

答案 1 :(得分:1)

此答案分为两部分:

  • 谷歌机器人
  • facebook,instagram和其他社交媒体机器人

对于 google机器人,您无需做任何额外的操作即可使google bot呈现您的所有页面数据。您可以阅读这些链接,以了解Google Bot如何呈现SPA。约翰·穆勒(John Mueller)创建了google group,以帮助开发人员解决他们对与SPA打交道时Google bot的工作方式和工作方式的疑问。

简而言之,如果您的网站管理员以Google身份获取可以正常工作,那么您就不必担心Google机器人会将页面编入索引了。您所需要做的就是创建正确的站点地图并正确生成标题元标记

对于社交媒体漫游器(例如Facebook抓取工具),您需要并入 angular Universal ,以便您的页面具有适当的共享预览。要实现社交共享,您必须使用resolve从后端获取数据。
例如 routing.module.ts 应该具有在初始化组件之前从后端获取数据的决心

        path: 'content/:id',
        component: contentDetailComponent,
        resolve: {
          content: DetailResolve
        }