小编siv*_*umm的帖子

Angular 路由器导航更改 url,但不渲染组件

我正在开发一个带有路由和路径参数的角度应用程序。单击按钮即可调用一个函数,将用户重定向到具有相同路径参数的新 URL。虽然浏览器中的URL发生变化,但app-routing.module.ts中定义的相应组件并未加载。如果我再次刷新页面,则会呈现正确的页面。

这个想法是,学生获得一个带有哈希标记的唯一 URL(例如/student/33192c29aa8e449e94f3a1c4eef43ca8),这向他展示了一些指导原则。然后点击一下,他应该被转发到具有相同令牌的注册页面(例如/student/registration/33192c29aa8e449e94f3a1c4eef43ca8

应用程序路由.module.ts

const routes: Routes = [
  ...
  { path: 'student/registration/:token', component: RegistrationsComponent },
  { path: 'student/:token', component: GuidelinesComponent },
  ...
];
Run Code Online (Sandbox Code Playgroud)

指南.component.html

forwardToRegistration(): void {
  this.router.navigateByUrl('/student/registration/' + this.studentToken);
}
Run Code Online (Sandbox Code Playgroud)

URL 在浏览器中正确更新,但 RegistrationComponent 未呈现。

感谢您的帮助!

redirect routes url-routing path-parameter angular

16
推荐指数
2
解决办法
2万
查看次数

标签 统计

angular ×1

path-parameter ×1

redirect ×1

routes ×1

url-routing ×1