Allow routes to be completely customized

This is a backport of some changes from the 2.0 branch.
I vaguely feel like this would be nicer extracted as a separate method.