【问题标题】:Routes: redirect to a separate page路由:重定向到单独的页面
【发布时间】:2021-06-08 15:22:47
【问题描述】:

我在应用组件 html 中有这个:

 <h1 class="title">{{ title | uppercase }}</h1>
 <app-discography-container></app-discography-container>
 <app-total-albums></app-total-albums>
 <app-single-album></app-single-album>
 <router-outlet></router-outlet>

然后我有另一个名为 video 的组件,其路由在 app-module 中声明:

 const routes: Routes = [{ path: 'video', component: VideoComponent }];

app-discography 组件中我有这个:

 <a routerLink="/video" target="_blank">
   lorem ipsum 
 </a>

当我点击链接“lorem ipsum”时,我会重定向到视频路径,但我也有组件app-total-albumsapp-single-album,但我不想要它们......我想要它将我重定向到一个单独的页面

【问题讨论】:

  • 你的角度版本是什么?在订阅中,我采用当前的路线路径。

标签: angular redirect routes angular-ui-router


【解决方案1】:

您好,我想我了解您的问题。您不想在视频页面中显示 app-total-albums 和 app-single-album 组件。因此,我为您的场景制作了一个 stackblitz 链接,请检查并告诉我这是否是您需要的。

https://stackblitz.com/edit/angular-ivy-fhpdqy?file=src/app/app.component.html

【讨论】:

  • 正是我想要的!太感谢了!你能解释一下你做了什么吗?我不明白this.router.events 从您使用NavigationEnd 开始的部分......
  • 你的角度版本是什么?这个问题在你当地解决了吗?每当路由以角度结束时,我们都可以使用该订阅获取该信息。所以我将当前的 url 路径作为 /videos.. 所以基于此我将这两个额外的组件隐藏在 app.component.html 中。
猜你喜欢
  • 2012-07-22
  • 1970-01-01
  • 1970-01-01
  • 2018-12-04
  • 2016-03-23
  • 1970-01-01
  • 2010-11-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多