[英]Router.Navigate doesn't work after updating Router 3.0.1 to 3.4.1
const myRoutes: Routes = [
{ path: "error", component: ErrorComponent, pathMatch: "full" },
{ path: "", component: HomeComponent }
];
我有以上路線。 默認情況下,它啟動HomeComponent,並在構造函數中,它具有檢查導致ErrorComponent的錯誤的條件。
this.router.navigate(["/error"]);
但是,更新路由器后,除了其他角度庫和依賴項。 這不再起作用。 URL路由到錯誤路徑,但未啟動組件。 我在構造函數中有一個斷點,但沒有遇到問題。 控制台中也沒有錯誤。 我試圖將ErrorComponent設置為默認頁面,只是為了檢查組件本身是否出了問題,但實際上是在加載,而不是當路徑與組件關聯時。
不知道它是否相關,但是我還沒有進行任何延遲加載,因此所有組件都是在開始時構建的。
我查看了文檔,看是否有任何差異。 我還嘗試將呼叫更改為:
this.router.navigate(["error"], { relativeTo: this.route });
//where "route" is ActivatedRoute
我將路徑移動到了下定義的路線
RouterModule.forChild()
不知道為什么下
RouterModule.forRoot()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.