gpt4 book ai didi

angular - router.navigate 更改 URL,但不呈现组件

转载 作者:太空狗 更新时间:2023-10-29 17:26:01 24 4
gpt4 key购买 nike

而不是使用 <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);

关于angular - router.navigate 更改 URL,但不呈现组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46179226/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com