You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular+Scully生成静态页内容错误且无Meta标签求助

问题概述

我用Angular v14搭建了一个简单网站,目标是通过Scully v2.1.41为网站添加SEO及Meta标签,所有操作均在前端完成,无服务器/请求交互。

核心问题
Scully能够识别所有带参数的路由并生成对应的静态HTML文件,但生成的文件仅包含主页内容,而非对应子页面的内容;同时生成的页面没有Meta标签,该问题需要先解决内容生成错误后再处理。

已尝试方案
  • 重新安装Scully,升级Angular及Scully版本
  • 为Scully添加如下配置,将生成延迟至25秒以确保内容渲染完成:
    ScullyLibModule.forRoot({
          useTransferState: true,
          alwaysMonitor: false,
          manualIdle: true,
        })
    
  • 尝试将所有路由添加至extraRoutes配置
  • 尝试多种添加Meta标签及标题的方式,当前使用Angular内置服务实现
相关代码

1. Scully配置

import {ScullyConfig} from '@scullyio/scully';
import {HandledRoute, registerPlugin} from "@scullyio/scully"
import {RUNES_D2R} from "./src/app/services/runes/models/Runes";

export const config: ScullyConfig = {
  projectRoot: './src',
  projectName: 'd2r-runes',
  distFolder: './dist/d2r-runes',
  outDir: './dist/static',
  defaultPostRenderers: [],
  routes: {
    '/runes/:runeId': {
      type: 'runes',
    },
  },
};

// Generate all routes with a plugin
function runesPlugin(route: string, config = {}): Promise<HandledRoute[]> {
  const rs = RUNES_D2R.map((r) => {
    return {route: '/runes/' + r.key}
  })

  return Promise.resolve(rs);
}

const validatorRunes = async (conf) => [];
registerPlugin('router', 'runes', runesPlugin, validatorRunes);

2. SEO服务

@Injectable({
  providedIn: 'root'
})
export class SeoService {
  constructor(private ts: Title, private meta: Meta, private router: Router, private scully: ScullyRoutesService) {
    this.router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe((ev: RouterEvent) => {
      this.setTags(ev.url);
    });
     
    this.scully.getCurrent().subscribe((link) => {
      const url = link.route;
      this.setTags(url);
    });
  }
  
  setTags(url: string) {
    // Sets tags correctly when I ng-serve
  }
}

内容的提问来源于stack exchange,提问作者Martin Antonov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 09:30:50