router.navigate 更改了 URL,但未渲染组件
router.navigate changes the URL, but is not rendering the component
我愿意使用带参数的函数将我重定向到页面,而不是在我的模板中使用 <a href="/my-path/{{my_param}}"></a>
。
所以,这就是我在 .ts 文件中构建函数的方式:
redirectToChat(my_param){
this.router.navigate(['./my-path/' + my_param ]);
}
以及我在模板中的调用方式:
<div (click)="redirectToChat(my_param)">
...
</div>
它更改 URL,但不渲染组件。
我在我的组件中导入了这个:
import { Router, ActivatedRoute, ParamMap } from '@angular/router';
我在构造函数中使用了它:private router: Router
你能帮我正确渲染组件吗?我还能如何使用函数将用户重定向到页面?
您正在混合导航(到组件)和按 url 导航。
您是否尝试过 navigateByUrl?
this.router.navigateByUrl('./my-path/' + my_param);
我愿意使用带参数的函数将我重定向到页面,而不是在我的模板中使用 <a href="/my-path/{{my_param}}"></a>
。
所以,这就是我在 .ts 文件中构建函数的方式:
redirectToChat(my_param){
this.router.navigate(['./my-path/' + my_param ]);
}
以及我在模板中的调用方式:
<div (click)="redirectToChat(my_param)">
...
</div>
它更改 URL,但不渲染组件。 我在我的组件中导入了这个:
import { Router, ActivatedRoute, ParamMap } from '@angular/router';
我在构造函数中使用了它:private router: Router
你能帮我正确渲染组件吗?我还能如何使用函数将用户重定向到页面?
您正在混合导航(到组件)和按 url 导航。 您是否尝试过 navigateByUrl?
this.router.navigateByUrl('./my-path/' + my_param);