简体   繁体   English

Angular ::从嵌套插座链接到父“路由器插座”

[英]Angular :: Link to parent 'router-outlet' from a nested outlet

I have a component within a nested router-outlet, but would like to create a link to a route that is in the parent's router-outlet. 我在嵌套的路由器出口中有一个组件,但想创建到父级路由器出口中路由的链接。 I am not sure what code you guys would want to see for me to explain this? 我不确定你们要看什么代码来解释这个问题?

You can point to anywhere in your app with routerLink regardless of where you are. 无论routerLink在何处,都可以使用routerLink指向应用程序中的任何位置。 It is just the matter of how you set the route. 这仅取决于您如何设置路线。 If you start the route with / it means from base (don't forget to set the base in your HTML). 如果您使用/开头路由,则表示从基础开始(不要忘记在HTML中设置基础)。

If you use ./ it is relative to where you are. 如果使用./ ,则相对于您所在的位置。

So let's assume you have two main routes, admin and frontpages , which have their own modules. 因此,假设您有两条主要路线, adminfrontpages ,它们有各自的模块。 Inside admin there is a users route and inside frontpage there is about route. 在管理员内部有一条用户路由,在首页内部有一条关于路由。 You can have a link to admin from about like this: 您可以从链接到admin,如下所示:

<a routerLink="/admin/users">Admin</a>

I created this stackblitz for you to checkout. 我创建了这个堆叠闪电战供您结帐。

我无法从模板执行此操作(也许看到了这个答案,有人可以向我展示如何从模板执行此操作),但是我能够通过如下方式进行程序设计使其工作:

this.router.navigate(['../../account-view/' + id], { relativeTo: this.route.parent });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM