Skip to content

Router navigation with lazy loading modules.  #17957

Closed

Description

@AndriiDidkivsky

I'm submitting a ...

[x] Bug report 

Current behavior

Hi, we have a few lazy-loading modules and router's configured like:

{
    path: 'parent',
    component: Parent,
    children: [
        {
            path: child1,
            loadChildren: 'pathToModule1'
        }
        {
            path: child2,
            loadChildren: 'pathToModule1'
        }
    ]
}

- child1 
{
    path: '', 
    component: Child1 
}

- child2 
{
    path: '', 
    component: Child2 
}

So, when i'm on the Child1 a wanna navigate to child 2 with
this.router.navigate(['../child2'], {relativeTo: this.activatedRoute})

And we get parent/child1/child2

But in cause of empty section added with lazy loading module configuration i should use
this.router.navigate(['../../child2'], {relativeTo: this.activatedRoute})
Because in fact we have parent/child1 + ''

Expected behavior

We get parent/child2
Is there any way to change this behaviour ?
Becouse with many nested lazy loading modules we'll get a littlebit
empty sections and we'll write ../../../../../../sibling to go sibling route.

Minimal reproduction of the problem with instructions

any application with lazy loading modules. Just try navigate to sibling route.
plunker
go down to member and try go back with two buttons.
Only ./../../../ is working.

What is the motivation / use case for changing the behavior?

Please tell us about your environment


Angular version: 4.1.3


Browser: any

Activity

  1. AndriiDidkivsky commented on Jul 7, 2017

    @AndriiDidkivsky
    Author

    In my app activatedRoute.pathFromRoot looks pretty strange.

    Each activatedRoute has component property and if extract it array looks like

    activatedRoute.pathFromRoot.map(x = >x.component)
    // [AppComponent, AccountContainer, undefined, LoansContainer, undefined, SearchContainer]
    

    So, before every lazy-module we have undefined component.

  2. AndriiDidkivsky commented on Jul 12, 2017

    @AndriiDidkivsky
    Author

    Guys, i've added plunker. Hope it'll help.

  3. djleonskennedy commented on Jul 12, 2017

    @djleonskennedy

    Hello all, totally critical issue, is there any plans to fix it, or suggest workaround

    Thank you

  4. ruslan-butyk commented on Jul 12, 2017

    @ruslan-butyk

    +1
    Did someone response?
    Fix this issue will be very helpful for me.

  5. otsmyg commented on Jul 13, 2017

    @otsmyg

    Anybody fixed this?

  6. jasonaden commented on Jul 18, 2017

    @jasonaden
    Contributor

    Thanks for the issue. We will discuss this one in the next couple days and update here.

  7. AndriiDidkivsky commented on Jul 18, 2017

    @AndriiDidkivsky
    Author

    Thx, guys.

  8. jasonaden commented on Jul 18, 2017

    @jasonaden
    Contributor

    @AndriiDidkivsky Do you happen to know if this is directly related to lazy loading or not? In other words, would this work if you weren't using lazy loading, but still using a children array?

    Basically wondering if this relates to lazy loading or routing in general.

  9. AndriiDidkivsky commented on Jul 19, 2017

    @AndriiDidkivsky
    Author

    @jasonaden , this relates just for lazy loading. I'll check again today and let you know.
    I can create another plunker, without lazy loading if needed

  10. AndriiDidkivsky commented on Jul 19, 2017

    @AndriiDidkivsky
    Author

    @jasonaden , it's completely lazy-loading issue. Here is the same plunker but without lazy loading and it works correctly. We go parent route with ./../ unlike of previous version.

  11. AndriiDidkivsky commented on Jul 26, 2017

    @AndriiDidkivsky
    Author

    Guys, any updates of this issue? We,re writing the big app and this thing is very important for us.

    Tnx.

  12. issasami commented on Aug 9, 2017

    @issasami

    Any updates about issue?

  13. undermoodzyx commented on Aug 23, 2017

    @undermoodzyx

    I met the same question.

    this.router.navigate(['/lazy-module'])
    

    It seems that the router.navigate doesn't work for lazy module. (we are using ng.version: 4.1.3)
    Below just a temporary solution using a tag with routerLink prop.

    <a routerLink="/lazy-module-name">lazy-module-name</a>
    
  14. issasami commented on Aug 23, 2017

    @issasami
  15. 27 remaining items

  16. uvconnects commented on Aug 2, 2018

    @uvconnects
  17. adorep commented on Aug 10, 2018

    @adorep

    This bug hits me again and again and again. Can't believe that it's not going to be fixed.
    Why is something as fundamental as relative navigation left broken?

  18. uvconnects commented on Aug 10, 2018

    @uvconnects
  19. bertvan commented on Sep 18, 2018

    @bertvan

    +1

  20. flyingsolo62 commented on Oct 1, 2018

    @flyingsolo62

    I'm a newbie at Angular and have been trying to figure this problem myself out for a weekend. I think I finally have 'an' answer. Since you're lazy loading the modules, any where you use this.router.navigate(this.returnUrl), for example, you must add the name of the child module at the beginning. For me it was this.router.navigate(['/admin + this.returnUrl]);

  21. cknolla commented on Jan 21, 2019

    @cknolla

    I thought for sure I was doing something wrong for such a fundamental functionality to be broken, and I spent a couple days banging my head into this problem. Amazing that this could be open for a year and a half. Makes me question my use of Angular.

  22. antwalls commented on Jan 27, 2019

    @antwalls

    I'm in 7.1.4 and facing the same problem. I think the whole router thing goes against "convention over configuration" and its too messy and complicated, NOTHING works as expected, and the information supplied in documentation is not sufficient. This is very discoraging, im tired and wasting time trying to figure out how this damm thing works. I'm going to try another framework, Screw this!

  23. jbonfante commented on Jan 27, 2019

    @jbonfante

    There appears to be a fix in this PR #26990

    but you may have to modify the router config for it to take effect. Have not tried this yet in 7.

  24. Humberd commented on May 7, 2019

    @Humberd
    Member

    Any updates?

  25. hansmaad commented on May 9, 2019

    @hansmaad

    I had to add the relativeLinkResolution option to the app routing config. It's strange that the buggy behaviour is selected by default.
    https://angular.io/api/router/ExtraOptions#relativeLinkResolution

    @NgModule({
      imports: [RouterModule.forRoot(routes, {
        relativeLinkResolution: 'corrected'
      })],
      exports: [RouterModule]
    })
    export class AppRoutingModule { }
  26. Humberd commented on May 9, 2019

    @Humberd
    Member

    @hansmaad Thank you. Your solution works like a charm.

  27. vladimiry commented on May 9, 2019

    @vladimiry

    I had to add the relativeLinkResolution option to the app routing config.

    Good finding. It was fixed more than a year ago #22394 but appeared here only now.

  28. angular-automatic-lock-bot commented on Oct 27, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  29. locked and limited conversation to collaborators on Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions