Modified toRoute to use the redirection code as well