【问题标题】:Angular 5 Component not removed on child route changed子路由上未删除的Angular 5组件已更改
【发布时间】:2018-05-28 05:15:16
【问题描述】:

嘿,我的 Angular 5 应用程序有问题。我创建了一个带有一些组件路由的简单应用程序。路由看起来像:

{ path: '', component: SetupComponent, pathMatch: 'full' }, // here we can add a landingpage
{ path: 'setup', component: SetupComponent },
{
    path: 'lan/:reference', component: LanComponent, // use special layout here which is defined in LanComponent
    children: [
        { path: '', redirectTo: 'dashboard', pathMatch: 'full' },
        { path: 'dashboard', component: DashboardComponent },
        { path: 'attendees', component: AttendeesComponent },
        { path: 'games', component: GamesComponent },
        { path: 'royal-beefs', component: RoyalBeefsComponent },
    ]
},
{path: '**', component: SetupComponent}

路由运行就像一个魅力,但如果我在这些子路由之间切换,旧子路由不会从 dom 中删除。

如果我在根路由之间切换,一切正常。如果我将子路由设置为绝对路由,它也可以工作。

index.html

<body class="m-page--fluid m--skin- m-content--skin-light2 m-header--fixed m-header--fixed-mobile m-aside-left--enabled m-aside-left--skin-dark m-aside-left--offcanvas m-footer--push m-aside--offcanvas-default">
<div class="m-grid m-grid--hor m-grid--root m-page">
  <app-root></app-root> <!-- app.component.ts -->
</div>
</body>

app.component.html

<router-outlet></router-outlet>

lan.component.html

<app-header-nav></app-header-nav>
<!-- begin::Body -->
<div class="m-grid__item m-grid__item--fluid m-grid m-body">
  <div class="m-grid__item m-grid__item--fluid m-wrapper">
    <router-outlet></router-outlet>
  </div>
</div>
<!-- end:: Body -->
<app-footer></app-footer>

在games.component.html 和其他只有内容。 链接将使用 routerLink 生成,例如:

[routerLink]="['/lan', params.reference, 'dashboard']"
[routerLink]="['/lan', params.reference, 'attendees']"

作为提示:我首先开发了这个应用程序,没有任何复杂的设计。一切正常。现在我想集成 Metronic 仪表板主题,我遇到了这个问题。 如果有人有解决方案,请发布:)

更新: 以下是主题的一些链接:

https://keenthemes.com/metronic/documentation.html

https://keenthemes.com/metronic/preview/?demo=demo12

【问题讨论】:

标签: angular angular5 parent-child angular-routing metronic


【解决方案1】:

我找到了答案! 在我的 html 文件中,我有一个指令 unwraptag。模板需要这个。 我删除了它,一切正常。在指令文件中,选择器被标记为 eslint 错误。这是选择器:'[appunwraptag]',

【讨论】:

    猜你喜欢
    • 2023-03-27
    • 1970-01-01
    • 2018-08-10
    • 2018-09-15
    • 1970-01-01
    • 1970-01-01
    • 2017-08-19
    • 2019-08-06
    • 2018-02-20
    相关资源
    最近更新 更多