[英]Angular Different routes same component
我在我的app.routing.ts中做到了:
{ path: 'profile/questionnaire', canActivate: [ AuthGuard], component: UprofileComponent},
而這在我的html文件中:
<div id="testButton">
<button class="col-md-3" id="colorBBox" routerLink="profile/test" (click)="hide();">Test1</button>
</div>
<div id="showTest1 style="display:none;> ...</div>
通過單擊按鈕“ hide()”被稱為:
hide(){
document.getElementById('testButton').style.display = 'none';
document.getElementById('showTest1').style.display = 'block';
this.showTest1();
}
問題:應該是routerLink =“ profile”,應該是routerLink =“ profile / test” ...兩者都是routerLink =“ profile” ..有什么想法嗎? 兩個div在.ts文件上共享一個html
為了獲得理想的結果,您可以從組件更改URL。 從@angular/router
導入Router
import { Router } from '@angular/router';
然后注入構造函數
constructor(private router:Router) {
}
然后根據某些條件從hide()
函數導航
this.router.navigate(['profile/test']);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.