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

如何在Sylius 1.11.5的sylius-standard中修改Taxons路由

Sylius 1.11.5 将Taxon路由从/taxons修改为/categories实现方案

1.11版本无需修改vendor源码,也不需要使用2018年旧版已废弃的事件监听方案,按以下步骤操作即可:

  • 新建路由覆盖配置:在项目config/routes/目录下创建taxon_route_override.yaml文件,写入以下配置,该配置优先级高于Sylius核心默认路由:
# 重写Taxon详情页路由
sylius_shop_taxon_index:
    path: /categories/{slug}
    methods: [GET]
    defaults:
        _controller: sylius.controller.taxon::indexAction
        _sylius:
            template: "@SyliusShop/Taxon/index.html.twig"
            repository:
                method: findOneBySlug
                arguments:
                    - $slug
                    - "expr:service('sylius.context.locale').getLocaleCode()"
  • 兼容旧路径跳转:在上述配置文件末尾追加内容,给原有/taxons路径配置301永久重定向,既避免路由冲突,也能兼容旧链接访问、不影响SEO效果:
# 旧路径301跳转到新路由
sylius_shop_taxon_legacy_redirect:
    path: /taxons/{slug}
    methods: [GET]
    defaults:
        _controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction
        route: sylius_shop_taxon_index
        permanent: true
  • 验证配置生效:执行以下命令清空缓存并检查路由配置:
php bin/console cache:clear
php bin/console debug:router sylius_shop_taxon_index

命令返回的路径字段显示为/categories/{slug}即配置成功。

注意事项:

  1. 项目中所有Taxon链接请统一使用path('sylius_shop_taxon_index', {slug: taxon.slug})的方式生成,不要硬编码路径前缀,避免后续调整路由时需要批量修改代码。
  2. 上述配置兼容Sylius 1.11版本的多语言、Taxon面包屑生成、分类页筛选等原生功能,不会影响原有业务逻辑。
  3. 2018年旧方案失效的核心原因是1.11版本调整了ShopBundle路由的加载优先级,旧方案自定义路由加载顺序晚于核心路由,会被原生规则覆盖,无法生效。

内容的提问来源于stack exchange,提问作者Stan Vanhoorn

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.28 08:24:15