Search code examples
angulartypescriptangular-routing

Lazy loading route angular


I've been using Angular for a long time I know how routes work but I wanted to try something new for me using lazy loading, as you can see in my I'm trying to navigate from one point to another but something is wrong or maybe not possible.

thanks.

ts.file

this.router.navigate(['../delta']);

app.routing.module.ts // root file

const routes: Routes = [
 {
  path:delta,
  loadChildren: () => import('./delta/delta.module').then(m => m.DeltaModule.);
 }
]

is it possible to navigate like this?


Solution

  • If you want to use that relative syntax, then you should do something like this:

    constructor(private route:ActivatedRoute,private router:Router){}
    
    ...
    
    this.router.navigate(['../delta'], { relativeTo: this.route });