1

I have a route with an optional parameter like:

/foo/bar/{baz}

{baz} is optional.

When accessing that route by a value for baz, the page contents are correct, but the breadcrumb is incorrect and caches the first one that you visit. This makes the breadcrumb incorrect. These are paths that are accessible in the admin area only.

Is there a way to make the breadcrumb correct?

Edit: is the route cache wrong or the menu cache?

9
  • How is the breadcrumb created, is it automatic, or did you do it custom?
    – Jaypan
    Commented Jul 6, 2022 at 14:43
  • Automatic. This is a standard Controller and route with menu link(s) (for each path to expose) via yaml file.
    – Kevin
    Commented Jul 6, 2022 at 14:49
  • What are the cache contexts on the breadcrumb?
    – sonfd
    Commented Jul 6, 2022 at 14:52
  • Not sure yet, I haven't implemented any breadcrumb.
    – Kevin
    Commented Jul 6, 2022 at 14:58
  • This is not possible that you haven't implemented any breadcrumb module, contrib or custom. The default is /foo/bar on a route /foo/bar/{baz} and the cache context is url.path.parent ignoring intentionally the last part of the path for cache efficiency. So the issue you've described can't happen in Drupal out of the box.
    – 4uk4
    Commented Jul 6, 2022 at 15:45

1 Answer 1

0

In this case, you need to implement a custom breadcrumb, then add a cache context for the URL.

How to create a custom breadcrumb: https://www.drupal.org/node/2876622

Cache contexts: https://www.drupal.org/docs/drupal-apis/cache-api/cache-contexts

Or, you may be able to work something out with the Custom Menu Breadcrumbs module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.