Skip to content

Navigating with outlets is confusing: outlets map does not apply to consumed segments #13523

Closed

Description

@colltoaction

I'm submitting a ...

[X] bug report

Current behavior

I have some routes like:

const routes = [
    { path: "", component: HomeComponent, pathMatch: "full" },
    { path: "profile", component: ProfileComponent },
    { path: "menu", component: MenuComponent, outlet: "sidebar" },
];

When the route http://localhost/(sidebar:menu) is open, then I'm able to remove the named outlet and go to http://localhost/ by clicking an anchor like the following:

<a [routerLink]="['', {outlets: {sidebar: null}}]">
    Close
</a>

What doesn't work is navigating away from the sidebar and also going to another route like http://localhost/profile.

<a [routerLink]="['/profile', {outlets: {sidebar: null}}]">
    Close
</a>

The link that is rendered is http://localhost:3971/profile(sidebar:menu)

Expected behavior

The link that should be rendered is http://localhost:3971/profile.

Repro

https://github.com/tinchou/router-repro

Please tell us about your environment:

Windows 10, Visual Studio 2017

  • Angular version: 2.3.1 (didn't work with 2.1.0 either)

  • Browser: all

  • Language: TypeScript 2.0.10

Activity

  1. colltoaction commented on Dec 16, 2016

    @colltoaction
    Author

    Update: Router.navigate doesn't work either. E.g. the following doesn't work:

    this.router.navigate(["/profile", { outlets: { sidebar: null } }]);

    Workaround: add a click handler and call navigate a second time, but only after the first one completes.

    this.router.navigate(["/profile"]).then(() =>
                this.router.navigate([".", { outlets: { sidebar: null } }]));
  2. vicb commented on Dec 16, 2016

    @vicb
    Contributor

    Please provide a quick repro. Thanks.

  3. colltoaction commented on Dec 16, 2016

    @colltoaction
    Author

    Created a new project with the latest cli and then added the components as explained above. Please take a look: https://github.com/tinchou/router-repro.


    EDIT

    Just tried to use ng github-pages:deploy but it fails trying to run git rm -r. Anyway, I copied the contents from /dist and deployed them manually, and here's a live demo!

    https://tinchou.github.io/router-repro/

  4. vicb commented on Dec 16, 2016

    @vicb
    Contributor

    👍

  5. wKoza commented on Dec 16, 2016

    @wKoza
    Contributor

    In the vsavkin's book, he says :

    `We can also remove segments by setting them to ‘null’.

    router.navigate([{outlets: {popup: null}}])`

    But he never set a path and a outlet. In this case, we can use

    <a [routerLink]="[{outlets: {primary: 'profile',sidebar: null}}]">

    If it can help

  6. colltoaction commented on Dec 16, 2016

    @colltoaction
    Author

    @WilliamKoza it seems to work using the primary outlet. Now I found it in the docs and it makes sense:

    outlet: The name of the RouterOutlet used to render the route. For an unnamed outlet, the outlet name is primary.

    This works perfect for me, thanks a lot (but I believe the issue still stands).

    Just one gotcha: in my real application it only works if specifying an empty string as the first parameter <a [routerLink]="['', {outlets: {primary: 'profile', sidebar: null}}]">

  7. nischi commented on May 16, 2017

    @nischi

    same issue here. i try to close the a modal window. I have a outlet called "modal" and there i load my modal window component. If i want to close it (without knowing where i'm) with modal: null it routes to the modal again.

  8. ragv1 commented on Jul 2, 2017

    @ragv1

    same issue. i have a named outlet call popup, just like in the docs. when i try to close it with:
    this.router.navigate([{ outlets: {popup: null }}]);
    It just does nothing.

  9. Almar commented on Jul 21, 2017

    @Almar

    @ragv1, have you tried this.router.navigate(['', { outlets: {popup: null }}]);?

  10. 27 remaining items

  11. added a commit that references this issue on Dec 28, 2020
    8c8466c
  12. atscott commented on May 24, 2021

    @atscott
    Contributor

    Closed by #40272

  13. angular-automatic-lock-bot commented on Jun 24, 2021

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

  14. locked and limited conversation to collaborators on Jun 24, 2021
  15. added a commit that references this issue on Aug 15, 2023
    46d7bd2
  16. added 2 commits that reference this issue on Aug 15, 2023
    da68bea
    6791f41
  17. added a commit that references this issue on Jan 23, 2024
    219c04b
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