Dynamic Routing of Ingress based on urls from database/service

I have following requirement mapping urls to kubernetes services:
/uuid1/name1: service A
/uuid1/name2: service B
/uuid2/name2: service A
...
...

Based on uuid and name, the request should be routed to corresponding service.
The mapping of url to service is dynamic as new names/uuids are added/removed to database.

Any suggestions, how I can achieve the same/similar with traefik's Kubernetes Ingress/Gateway API/IngressRoute?

Something similar can be achieved using nginx ingress by leveraging lua and a locator/router service returning service name as a header. But I was looking for some better way to achieve this.