简体   繁体   中英

Angular Router always get back to Main Page

I've got a problem with Angular Router (Angular 11). That's my routing below:

{path: '', redirectTo: '/zaloguj', pathMatch: 'full'}
{path: 'zaloguj', component: LoginComponent}
{path: 'orzeczenia', component: ApiComponent}
{path: 'orzeczenia/:id', component: ShowDataComponent}
{path: 'kontakt', component: ContactComponent}
{path: 'konto', component: DashboardComponent}
{path: '**', component: PageNotFoundComponent}

I created the function (below) in one of my component:

showVerdict(): any {
this.router.navigate(['/kontakt']);

}

When I use this function, Angular goes to the Kontakt Route (ContactComponent), but after maybe 1 sec, redirects to MainPage. I changed the route to for example "konto", etc. however, the problem still occurs. Please help me!

I resolved the problem. It was trivial. I added the click event to an "a link", but I forgot to remove href="#"... Now, everything is fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM