簡體   English   中英

角4路由添加一個組件而不是替換它

[英]angular 4 routing adding a component rather than replacing it

我在動態加載的子模塊中配置了以下路由。
我不認為動態加載會引起問題,但可能是-所以我將其包括在內以供參考。

動態負荷

children: [
    {
        path: "dashboard",
        loadChildren: () => new Promise(resolve => {
            (require as any).ensure([],
                require => {
                    resolve(require("./dashboard/dashboard.module").DashboardModule);
                },
                "dashboard");
        })
    },

儀表板的路由模塊

const routes: Routes = [
    {
        path: "",
        component: ClearingDashboardComponent,
        data: {
            title: "Dashboard"
        }
    },
    {
        path: "logs",
        component: LogDisplayComponent,
        data: {
            title: "Logs"
        }
    }
];

登陸HTML如下所示

紅色儀表板組件

使用導航到LogDisplayComponent

const ne: NavigationExtras = {
    queryParams: { ... }
};
this.router.navigate(["dashboard/logs"], ne);

在HTML上方添加了一個新組件。
當然每個組件都應該替換內部HTML嗎?

在此處輸入圖片說明

LogDisplayComponentClearingDashboardComponent上方,當我單擊時,每次我以任何一種方式導航時都會添加一個新組件?

如何修復替換部件而不是添加新部件的路線?

我正在使用角4.4.4 ...

嘗試將您的版本更新到5+。 Angular團隊已經解決了這個問題。 有關更多信息,請檢查以下鏈接:

https://github.com/angular/angular/issues/17261

https://github.com/angular/angular/issues/13725

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM