Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何在谷歌上用角度预合成显示页面标题?_Angularjs_Html_Seo_Search Engine_Google Search - Fatal编程技术网

Angularjs 如何在谷歌上用角度预合成显示页面标题?

Angularjs 如何在谷歌上用角度预合成显示页面标题?,angularjs,html,seo,search-engine,google-search,Angularjs,Html,Seo,Search Engine,Google Search,基于超光速响应,我建立了一个Angular 1应用程序,没有Hashbang和html5Mode(true),并依靠Google执行javascript。该页面正在被谷歌编入索引,但动态标题和描述标签却没有 我的index.html标题如下所示: <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-widt

基于超光速响应,我建立了一个Angular 1应用程序,没有Hashbang和html5Mode(true),并依靠Google执行javascript。该页面正在被谷歌编入索引,但动态标题和描述标签却没有

我的index.html标题如下所示:

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <base href="/">

    <meta name="author" content="me">
    <meta name="robots" content="index,follow">

    <title ng-bind="meta.title">Temp Title</title>
    <meta name="description" content="{{meta.description}}">

    <!-- Scripts & CSS -->
</head>

临时职位
标题和描述已正确加载,但不会显示在Google上

我该怎么做


这项技术是否也适用于Facebook和其他社交网络?谢谢。

为什么不使用这样的东西


实际上,超光速响应有一个解决方案。HTML页头必须由服务器完全解析发送

因此,为了让这个解决方案发挥作用,我被迫在服务器端复制角度路由,并发送解析信息

我没有使用普通的html视图,而是改为.ejs,并将标题改为如下内容:

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <base href="/">

    <meta name="robots" content="index,follow">

    <script type="text/javascript"> 
        window.title = <%- JSON.stringify(precomposition) %>.title;
    </script> 

    <title ng-bind="title"><%= precomposition.title %></title>
    <meta name="description" content="<%= precomposition.description %>">
    <!-- More meta information -->
    <!-- Scripts & CSS -->
</head>
如果不是直接命中,Angular将处理标题更新(因为其他信息不会显示给用户)


它有一些不利之处,但自2015年10月以来,谷歌建议采用这种方法,而不是“逃逸的片段URL”。另外,我认为它比自托管的预呈现替代方案消耗的资源少很多,而且比付费的更便宜。

也许为爬虫预呈现页面会更有效,但我想知道是否有一种更简单的方法。@neptune是的,我正在尝试评估是否有可能避免这种方法并最终得到一个SEO友好的SPA。我正在尝试评估是否有可能避免这种方法并最终得到一个SEO友好的SPA。
//Express route
app.route('/').get(precomposition.render);

//precomposition
exports.render = function (req, res) {
    const precomposition = {title: 'tile', description: 'description'};
    res.locals.precomposition = precomposition;
    res.render('index.ejs');
};