简体   繁体   English

在 Typo3 routeEnhancer 中设置默认参数的问题

[英]Problem with setting default argument in Typo3 routeEnhancer

I have a Typo3 page that works with two URL parameters, "manuscript" and "type" (eg localhost/my-page?manuscript=samplemanuscript&type=description).我有一个 Typo3 页面,它使用两个 URL 参数,“手稿”和“类型”(例如 localhost/my-page?manuscript=samplemanuscript&type=description)。 "manuscript" is a mandatory parameter, while "type" is optional. “手稿”是必填参数,而“类型”是可选参数。

I use Route Enhancers to get rid of cHash in the URL. So I have created a yaml file to configure it.我使用 Route Enhancers 去除 URL 中的 cHash。所以我创建了一个 yaml 文件来配置它。

This configuration works fine without "defaults" section with both parameters in place, but when I add the defaults section to make "type" parameter optional, the URL localhost/my-page/samplemanuscript works fine, but localhost/my-page/samplemanuscript/description shows me the 404 error.此配置在没有“默认”部分且两个参数都已到位的情况下工作正常,但是当我添加默认部分以使“类型”参数可选时,URL localhost/my-page/samplemanuscript 工作正常,但 localhost/my-page/samplemanuscript /description 显示 404 错误。 Any ideas what's wrong with it?任何想法有什么问题吗?

I use Typo3 v10.4我使用 Typo3 v10.4

routeEnhancers:
  ManuscriptHierarchy:
    type: Simple
    limitToPages: [13]
    routePath: '/{manuscript}/{type}'
    defaults:
      type: ''
    aspects:
      manuscript:
        type: StaticValueMapper
        map:
          samplemanuscript: samplemanuscript
          samplemanuscript2: samplemanuscript2
      type:
        type: StaticValueMapper
        map:
          transcription: transcription
          description: description

PS聚苯乙烯

For debugging purposes, is there any appropriate way to check the final resolved URL (when I visit localhost/my-page/samplemanuscript/description)?出于调试目的,是否有任何适当的方法来检查最终解析的 URL(当我访问 localhost/my-page/samplemanuscript/description 时)?

The solution looks strange to me but it works by adding requirements:该解决方案对我来说看起来很奇怪,但它通过添加要求来工作:

routeEnhancers:
  ManuscriptHierarchy:
    type: Simple
    limitToPages: [13]
    routePath: '/{manuscript}/{type}'
    defaults:
      type: ''
    requirements:
      manuscript: '^(?:samplemanuscript|samplemanuscript2)$'
      type: '^(?:description|transcription)$'
    aspects:
      manuscript:
        type: StaticValueMapper
        map:
          samplemanuscript: samplemanuscript
          samplemanuscript2: samplemanuscript2
      type:
        type: StaticValueMapper
        map:
          transcription: transcription
          description: description

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM