angular - angular 11 不在订阅内导航
问题描述
问题是我无法重定向(URL 更改内容没有)
export class HomePageComponent implements OnInit {
constructor(private authService: MsalService, private activatedRoute: ActivatedRoute,
private router: Router) { }
ngOnInit(): void {
const self = this;
this.activatedRoute.queryParams.subscribe(params => {
if (this.authService.instance.getActiveAccount() != null) {
let redirectUrl = params['redirectUrl'];
if(redirectUrl !== undefined) {
self.router.navigateByUrl('/activate');
return true;
}
}
});
}
}
但是这段代码有效,为什么?router.navigateByUrl('/activate') 不在订阅范围内
ngOnInit(): void {
const self = this;
this.router.navigateByUrl('/activate');
this.activatedRoute.queryParams.subscribe(params => {
if (this.authService.instance.getActiveAccount() != null) {
let redirectUrl = params['redirectUrl'];
if(redirectUrl !== undefined) {
self.router.navigateByUrl('/activate');
return true;
}
}
});
}
我真的需要 redirectUrl 而不是现在硬编码
解决方案
推荐阅读
- spring-webflux - webflux如何处理全局错误,比如找不到404页面
- javascript - 如何在 SweetAlert 上使用换行符输出 CodeIgniter 验证错误消息?
- stanford-nlp - 如何在多线程中运行命令行 CoreNLP?
- c# - C# 和 ASP.NET - 使用 SQL 表中的结果从下拉列表填充网页文本框
- prolog - 用 Prolog 列表中的任何数字(例如 8)替换前 K 个出现的 1
- laravel - 信息未以模式显示,但没有错误,并且 Vue 组件在控制台中工作
- recursion - 使用递归在 lambda 演算中创建有序对列表
- javascript - JavaScript 中两个字符串之间的常用字母
- r - 替换矩阵中的值:在每一行中,最大值与最小值
- arrays - 在 do/until 循环中打印 Powershell 数组属性在循环第一次迭代后显示空白行