yamltypo3typoscripttypo3-10.x

Problem with setting default argument in Typo3 routeEnhancer


I have a Typo3 page that works with two URL parameters, "manuscript" and "type" (e.g. 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

P.S.

For debugging purposes, is there any appropriate way to check the final resolved URL (when I visit localhost/my-page/samplemanuscript/description)?


Solution

  • 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