在服务端渲染时添加global属性来模拟self。在main.server.ts文件中添加以下代码:
(global as any).self = { location: { origin: 'http://localhost:3000', }, };
这将在服务器端渲染时定义了self对象,包括location.origin属性。然后在在应用程序的任何组件中可以使用self对象。
上一篇:Angular服务器端渲染一直返回502错误
下一篇:Angular服务器端渲染(ssr)一直在等待不存在的文件