fix route undefined bug and add unit tests