Skip to content

Router links in @defer blocks not having correct relative route #54864

Closed

Description

@NachmanBerkowitz

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

17.2.1

Description

A RouterLink with a route of ./ should route to the activated route. (eg. <a [routerLink]="'./'" >Link One</a>). But when it is in a defer block, and it is a sibling of a component that imports from material it routes to the app root.
So
@defer(on timer(1000)) { <has-material/> <a [routerLink]="'./'" >Link One</a> } routes to the root.

image

Reproduction

StackBlitz link: https://stackblitz.com/edit/stackblitz-starters-prh2zk
Steps to reproduce:

  1. Have a RouterLink in a defer block that has a relative route
  2. Give it a sibling that imports from Material

Expected Behavior

The router link route should be relative to the current route.

Actual Behavior

The router link route is from the root. The 'ActiveRoute' seems to be incorrect.

Environment

  • Angular: >= 17.2.4
  • CDK/Material: 17.2.2
  • Browser(s): edge, chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows

Activity

  1. crisbeto commented on Mar 14, 2024

    @crisbeto
    Member

    This seems like either a framework or router issue. Material doesn't use the router at all. Transferring to the framework repo.

  2. added
    area: core
    core: defer
    on Mar 14, 2024
  3. modified the milestone: needsTriage on Mar 14, 2024
  4. alxhub commented on Mar 14, 2024

    @alxhub
    Member

    Likely related to the injector construction of @defer.

  5. JeanMeche commented on Mar 14, 2024

    @JeanMeche
    Member

    I could narrow it down a bit:

    The ActivatedRoute has an undefined route when in a defer block and having a import (whatever import).

    repro: https://stackblitz.com/edit/angular-repro-54864

  6. added
    P2
    on Mar 15, 2024
  7. 29 remaining items

  8. Yberion commented on Apr 16, 2024

    @Yberion

    Hello, it seems that I have the same problem there, I wanted to use defer blocks to load a different layout depending on the result of the BreakpointObserver, both having a router outlet for child pages.

    The problem occur with a component from Angular Material, it seems that the router and ActivatedRoute are not "synchronized" anymore.

    And it is at this point that we get different results from the router and the snapshot.

    The problem appears in the component that is defered LoaderComponent, no problem in the SomepageComponent (check console logs).

    The problem disappears if I remove MatButtonModule from LoaderComponent OR if I remove the defer block from SomepageComponent.

    I'm on Angular 17.3.4

  9. NachmanBerkowitz commented on Apr 16, 2024

    @NachmanBerkowitz
    Author

    This bug seems like the previous bug. Using a defer block around a component that imports 'something' causes issues with the ActivatedRoute in that component.

  10. AndrewKushnir commented on Apr 17, 2024

    @AndrewKushnir
    Contributor

    @Yberion @bboyle thanks for providing a repro. We've identified the root cause and I've created a PR with a fix: #55374. I will update this thread once the mentioned PR lands.

  11. added a commit that references this issue on Apr 17, 2024
    70a9973
  12. added a commit that references this issue on Apr 22, 2024
    5cf14da
  13. added a commit that references this issue on Apr 22, 2024
    9894278
  14. AndrewKushnir commented on Apr 25, 2024

    @AndrewKushnir
    Contributor

    FYI, the fix from PR #55374 was merged and released as a part of v17.3.6. Please let us know if the problem still exists after updating to v17.3.6.

  15. Yberion commented on Apr 25, 2024

    @Yberion

    Hello @AndrewKushnir, thanks a lot for the fix. I can confirm on my side that it is working now!

  16. angular-automatic-lock-bot commented on May 26, 2024

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

  17. locked and limited conversation to collaborators on May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2area: corearea: routerbugcore: defercore: distate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions