Getting access denied when altering user view route I want to display custom content for the user profile page instead of the entity view so I am altering the entity.user.canonical route and I am setting a custom controller and title compared to the entity view and page callback that is set by the UserRouteProvider. I am leaving the requirements athey are since I don't need to change anything regarding the permissions.

Strangely though I am still getting Access denied after I flush the cache. The code that I am using in my event subscriber that is run on the RoutingEvents::ALTER event is:

  $collection = $event-&gt;getRouteCollection();
    $route = $collection-&gt;get('entity.user.canonical');
    $route-&gt;setDefaults(array(
      '_controller' =&gt; '\Drupal\mymodule\Controller\UserController::profilePage',
      '_title' =&gt; 'Profile'
    ));


If I will use setDefault('_controller'...) instead of setDefaults() method it will work since I think the _controller has more priority over _entity_view but the _title does not have priority over _title_callback. So this is not a viable solution.

Any idea what the issue with that access might be? Does the _entity_access requirement require the _entity_view to be used instead of the controller? Should the presence of the entity in the url be sufficient?
Can't be sure as you haven't posted your controller, but my guess would be that you are not type hinting the argument there as UserInterface $user, so it doesn't get upcasted. That is required for _entity_access to work