[英]How to clear the dropdowns values when i navigate to back page in Angular 6
[英]I cant navigate to the index page, when i click back button in Angular
我有 Angular 項目。 在索引頁上我有一些按鈕,這讓我進入了另一個頁面。 當我想 go 返回索引頁時,我單擊瀏覽器的后退按鈕,然后出現一個白頁,而不是我的索引頁。 你有同樣的問題嗎?
據我所知,這不是 angular 路由的問題。 我建議檢查路由配置是否正確。
假設您已經在您的項目中設置了 angular 路由 ( this ),您必須確保正確注冊索引頁面的路由。 在你的app-routing.module.ts
中應該有這樣的東西:
const routes: Routes = [
{ path: 'another-page', component: AnotherPageComponent },
{ path: '', component: IndexPageComponent },
{ path: '**', redirectTo: '' }
]
在您的app.module.ts
中,確保已導入BrowserModule
和AppRoutingModule
。
我通過以下方式解決了這個問題:我給了我的索引頁(app.component.html)class“mainPage”
<div class="mainPage" #mainPage>
... // index page
</div>
然后我在 app.component.ts 中寫了如下代碼:
export class AppComponent implements OnInit{
@ViewChild('mainPage') buttons!: ElementRef;
constructor(private renderer: Renderer2, private el: ElementRef, private router: Router){
router.events.subscribe((eve : any )=>{
this.currentRoute = router.url;
if(this.currentRoute == '/'){
this.showIndex();
}
});
}
currentRoute : string = "";\
ngOnInit(): void {
}
hideIndex(){
this.renderer.addClass(this.buttons.nativeElement, "d-none");
}
showIndex(){
this.renderer.removeClass(this.buttons.nativeElement, "d-none");
}
title = '';
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.