在Angular 9中,你可以通过使用Router
服务的navigateByUrl
方法来实现在懒加载组件之外跳转到路径。下面是一个示例代码:
首先,在你的组件文件中导入Router
服务:
import { Router } from '@angular/router';
然后在组件的构造函数中注入Router
服务:
constructor(private router: Router) { }
接下来,你可以在需要跳转的地方调用navigateByUrl
方法来跳转到指定的路径:
this.router.navigateByUrl('/your-path');
你可以将'/your-path'
替换为你想要跳转的路径。
请注意,navigateByUrl
方法是一个异步方法,返回一个Promise
。你可以使用then
方法来处理导航完成后的逻辑:
this.router.navigateByUrl('/your-path')
.then(() => {
// 导航完成后的逻辑
});
通过这种方式,你可以在懒加载组件之外跳转到指定的路径。