#4695 Refactor setMatchedRouteName

Resubmitting with suggested changes.

See #4695.