Skip to content

Relative navigation to siblings broken with empty/component-less routes #19290

Closed

Description

@tiwieso

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x ] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Relative navigation with '../x' or '../../x' fails when crossing an empty/componentless/lazy-loaded route.

Minimal reproduction of the problem with instructions

I created a minimalistic plunkr, that covers this issue. It's not only related to lazy loaded, but also to componentless empty routes. The behavior also depends on the existence of deeper child routes, which 'toggles' whether ../x or ../../x router-links will work or fail.

Tested with Angular Version 4.3.6 and 4.4.3 (which is used in plunkr at the time of this writing).

-> plunkr <-

Just follow the instructions in the plunkr and watch the console.

The plunkr covers another issue with using multiple '..' commands for navigation, e.g.
[routerLink]="['..','..','home']"
which will result in urls containing double dots, like /a/../home

Expected behavior

It works in a consistent and expected way:

  • empty routes are treated as non-existent, when navigating with '..'-commands/paths
  • the existence of activated child routes does not change behavior

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

The current implementation is very confusing, and impossible to use correctly without analyzing the activated routes children, as their mere existence change the behavior (see plunkr). This makes a correct static configuration of the links impossible.

Environment


Angular version: 4.3.6, 4.4.3

Browser:
- [x ] Chrome (desktop) version 60

Might be related to #17957

Activity

  1. tiwieso commented on Sep 21, 2017

    @tiwieso
    Author

    I updated the plunkr to show a related issue with auxiliary routes affecting the navigation in a different way.

  2. bennadel commented on Oct 5, 2017

    @bennadel

    I just ran into this as well. The relative navigation kept trying to add the sibling as a sub-segment of the other sibling. Like, /sibling-a/(sibling-b). Adding the prefix helped.

  3. VamsiVempati commented on Nov 8, 2017

    @VamsiVempati

    @bennadel Hi Ben, you mentioned that adding the prefix helped, did it fix the issue with lazy loading and you were able to navigate from ../child-1 to ../child-2 instead of ../child-1/child-2 ? What exactly does adding the prefix mean sorry ? Thanks :)

  4. bennadel commented on Nov 8, 2017

    @bennadel

    @VamsiVempati sorry, I have not tried anything with lazy-loading yet. Regarding "prefix", I think what I meant was that I made them all absolute paths, rather than relative paths.

  5. bennadel commented on Nov 8, 2017

    @bennadel

    @VamsiVempati I think that maybe I was getting this issue and this other issue - #14662 - confused when I was talking about "prefix".

  6. added this to the Backlog milestone on Jan 23, 2018
  7. modified the milestones: Backlog, needsTriage on Feb 26, 2018
  8. haskelcurry commented on Dec 20, 2019

    @haskelcurry

    Hi, any updates on this? Having the empty route is a very common case

  9. atscott commented on May 27, 2020

    @atscott
    Contributor
  10. atscott commented on May 29, 2020

    @atscott
    Contributor

    relativeLinkResolution: 'corrected' is the fix for the issue described here. From the B2 component, [../b1] is the correct relative link, even when there is a child route present. It works in both cases. I've opened #37355 to make this option the default.

  11. angular-automatic-lock-bot commented on Jun 30, 2020

    @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.

  12. locked and limited conversation to collaborators on Jun 30, 2020
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