Extract future common code into `base_loader_tree` (#70284)
This is a pure refactoring in preparation for introducing an `app_route_loader_tree` in a future PR.
It enables reusing common logic for injecting imported modules from the app directory into both page and route entries.