元标记未针对根 URL www.domain.com 更新 [英] Meta tags are not updating for root URL www.domain.com

查看:30
本文介绍了元标记未针对根 URL www.domain.com 更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个部署在 firebase 上的 Angular8 通用应用程序.引用此网站 Angular 通用与 firebase

I am creating an Angular8 Universal application which is deployed on firebase. Referred this website Angular universal with firebase

当我在本地使用 express 服务器运行和服务应用程序时,所有路由都加载了更新的元标记.当我在 firebase 上部署应用程序时,一切正常,但根路径上的元标记没有更新.对于所有其他路线,它们都可以正常工作.当我打开检查元素时,元标记也在更新.我在 firebase.json 如何防止缓存 SPA 的 index.html 并将 server.ts 文件中的缓存"值设置为无缓存"

When I run and serve the application with express server locally all of the routes are loading with updated meta tags. When I deploy the application on firebase everything works fine but meta tags on root path are not updating. They work absolutely fine for all other routes. Also meta tags are updating when I open inspect-element. I have added some configuration for not caching the html file on firebase.json How to prevent caching for the index.html of an SPA and also set the "cache" value to "No-cache" in server.ts file as

app.get('*', (req, res) => {
  res.set('Cache-Control', 'public, max-age=0, s-maxage=0, no-cache');
  res.render('index', { req });
});

但对我来说没有任何效果.请帮忙.

But nothing worked for me. Please help.

推荐答案

这是一个与 firebase 云功能相关的问题.不会在根路径 (www.domain.com) 上调用云函数,因此不会在服务器端更新元标记.我通过在应用程序的根目录中创建一个文件夹test"并将所有数据从 dist/browser 文件夹复制到test"文件夹并将 index.html 文件重命名为其他内容(例如 index2.html)解决了这个问题.还使用以下行更新了 firebase.json 文件:

This is a issue related to firebase cloud function. The cloud function is not getting invoked on the root path (www.domain.com), hence not updating meta tags on server side. I solved this issue by creating a folder 'test' in the root directory of the application and copying all the data from dist/browser folder into 'test' folder and renaming the index.html file to something else (eg. index2.html). Also updated the firebase.json file with the following line:

....
"hosting": {
    "public": "test",
    ....

因此,每当输入 URL 时,firebase 都会搜索公共文件夹中的 index.html 文件,如果不存在 index.html 文件,它将调用我们的云函数.

So whenever a URL is entered firebase searches the index.html file in the public folder and If there is no index.html file present it will invoke our cloud function.

这篇关于元标记未针对根 URL www.domain.com 更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆