0

我怎樣才能限制組件加載回來按下。 其實我有三個組件A(正常組件),B(LoginComponent)和C(Otp驗證組件)。 我在點擊某個按鈕並從B到C驗證用戶時,從A路由到組件B. 現在在對組件C進行驗證後,我想回到組件'A',並且想要從歷史中刪除組件'B'和'C',以便在從瀏覽器按回來時它不加載'B'(LoginComponent )和'C'。 所以我怎麼能在angularjs 2中做到這一點。從角度刪除歷史記錄中的組件2

+0

我想你可以使用路線警衛。 [RouteGuards](https://angular.io/docs/ts/latest/guide/router.html#!#guards) –

+0

它們允許您掛鉤組件生命週期,讓您可以取消導航。 –

回答

2

從組件B和C導航時,通過選項replaceUrl:true在瀏覽器歷史記錄中將B替換爲C.

如:

//Navigating to state C 
this.router.navigate(["/C"], { replaceUrl: true }); 

結帳的documentation for replaceUrl

相關問題