Generate namespaced routes correctly for generators. Fix for #11532

As #11532, namespaced routes are not generated properly for generator commands. This PR tries to fix that.