简体   繁体   中英

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). "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.

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. Any ideas what's wrong with it?

I use 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)?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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