8 – How to get the parameter value from an ajax call in the page controller?


I have the following js code according to es6.

(($, Drupal) => {
  Drupal.behaviors.mymodule = {
    attach: () => {
      document.querySelectorAll("a").forEach(element => {
        element.addEventListener("click", e => {
            fetch("/mypath", {
              method: "POST",
              body: JSON.stringify({
                path: $(this).attr("href")
              }),
            });
        });
      });
    }
  };
})(jQuery, Drupal);

and in the page controller:

public function content(SymfonyComponentHttpFoundationRequest $request) {
  $path = $request->request->get('path');
}

But I am not getting the path. Can someone tell me how to get the path in my page controller?