Performance: optimize route recognition. Large speedup for apps with many resource routes. Closes #10835.