Below is my app.routing.ts
export const Approute: Routes = [
{
path: 'login',
component: LoginComponent
},
{
path: 'home',
component: HomeComponent,
children: [
{
path: 'dashboard',
component: DashboardComponent
},
{
path: 'trip-details',
component: TripDetailsComponent
}
]
},
{ path: 'not-found', component : NotFoundComponent },
{ path: '**', redirectTo: '/not-found' }
];
component.ts
viewDetails(details) {
...
this.route.navigate(['../trip-details']);
}
Above i have a component and am trying to navigate to another sibling component but am not able to navigate to http://localhost:4200/home/trip-details its redirecting me to http://localhost:4200/not-found.
Where am doing wrong?
You can specify relativeTo which route as shown below:
import {Router, ActivatedRoute } from '@angular/router';
constructor(private r: ActivatedRoute) { }
viewDetails(details) {
...
this.route.navigate(['../trip-details'], { relativeTo: this.r });
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With