我正在开发一个带有路由和路径参数的角度应用程序。通过单击按钮,将调用一个函数以将用户重定向到具有相同路径参数的新 URL。虽然浏览器中的 URL 发生了变化,但是 app-routing.module.ts 中定义的相应组件并没有被加载。如果我再次刷新页面,则会呈现正确的页面。
这个想法是让学生获得一个带有哈希令牌(例如/student/33192c29aa8e449e94f3a1c4eef43ca8
)的唯一 URL,这向他展示了一些指导方针。然后点击一下,他应该被转发到具有相同令牌的注册页面(例如/student/registration/33192c29aa8e449e94f3a1c4eef43ca8
)
应用程序路由.module.ts
const routes: Routes = [
...
{ path: 'student/registration/:token', component: RegistrationsComponent },
{ path: 'student/:token', component: GuidelinesComponent },
...
];
指南.component.html
forwardToRegistration(): void {
this.router.navigateByUrl('/student/registration/' + this.studentToken);
}
URL 在浏览器中正确更新,但 RegistrationComponent 未呈现。
谢谢您的帮助!