Since /data is used as path alias for a node, Drupal shows that node instead of using any route that a module defines for /data. If you were to set a node path alias to /admin/config/people/accounts, Drupal won't show the accounts setting page anymore.
If you want to change the render array used for a node, you need to implement hook_ENTITY_TYPE_view()
. You can compare $entity->id()
with the node ID to which you want add data in its render array.
use \Drupal\Core\Entity\EntityInterface;
use \Drupal\Core\Entity\Display\EntityViewDisplayInterface;
/**
* Implements hook_ENTITY_TYPE_view().
*/
function mymodule_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
if ($entity->id() == 3) {
// Change $build.
}
}