Skip to content

router-outlet should not affect layout (option to render as non-box/anchor) #64553

Open

Description

@MillerSvt

Which @angular/* package(s) are relevant/related to the feature request?

router

Description

is a marker element that does not contain the routed component’s DOM; the actual component root is rendered as a sibling after the outlet.
However, the outlet element itself still participates in layout (inline/box). This can interfere with CSS Grid/Flexbox flows, gaps, and alignment, forcing developers to add a global stylesheet rule like:

router-outlet { display: none; }

or similar hacks.

Related to: https://stackoverflow.com/questions/54868967/how-to-get-angulars-router-outlet-to-work-with-css-grid

Motivation

  • Avoid layout artifacts (extra empty grid/flex item, unexpected inline box).
  • Reduce boilerplate and “magic CSS” in every app and library.
  • Make router behavior consistent with other Angular structural anchors, which use comment anchors and do not create a layout box.

Proposed solution

(any of the following would solve the problem)

1. Opt-in comment anchor for outlets

Add a configuration/flag so that router-outlet uses a comment node anchor (like @if) instead of an element.
Possible shapes:

Router config:

provideRouter(routes, { outletAnchor: 'comment' /* | 'element' (default) */ });

Or attribute/boolean input on the outlet:

<router-outlet anchor="comment"></router-outlet>

Or provide control-flow directive:

@router-outlet;

@router-outlet (name: 'secondary');

@router-outlet { placeholder };

@router-outlet (name: 'secondary') { placeholder };

2. Documented & bundled style

Officially document and ship a built-in global style (or recommend it prominently in the Router docs) so apps don’t need to rediscover it:

router-outlet { display: none /* or display: contents */; }

Alternatives considered

Keep relying on app-level CSS (router-outlet { display:none }).
Works, but it’s non-obvious, duplicated across apps, and easy to miss (especially inside Shadow DOM).

Activity

  1. added this to the needsTriage milestone on Oct 21, 2025
  2. added a commit that references this issue on Oct 21, 2025
    38222c9
  3. crisbeto commented on Oct 21, 2025

    @crisbeto
    Member

    Something like #64562 should work for this case.

  4. added a commit that references this issue on Oct 21, 2025
    2bd764a
  5. atscott commented on Oct 22, 2025

    @atscott
    Contributor

    Every option seems just about as discoverable and forgettable as the css {display: none}. Everything requires a specific opt-in/out that you always have to remember in each instance if you need it.

  6. added a commit that references this issue on Mar 3, 2026
    8a4e294
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

      Sponsor
      SponsoredKunjungi sekarang
      Promo