Skip to content

Directive routerLink dont correctly work with empty fragment option #29683

@Dok11

Description

@Dok11

🐞 bug report

Description

When fragment of routerLink are empty the anchor save # in href.
But expected will remove # character for use clean url.

So, for fix this issue I need use two diffrent temaplates of one link: with fragment and without.
I think this is not pretty decision.

And I think the solution located something here: https://github.com/angular/angular/blob/7.2.x/packages/router/src/url_tree.ts#L293

Now:

const fragment =
        typeof tree.fragment === `string` ? `#${encodeUriFragment(tree.fragment !)}` : '';

But it should be something like this:

const fragment = (typeof tree.fragment === `string` && tree.fragment)
    ? `#${encodeUriFragment(tree.fragment !)}` : '';

🔬 Minimal Reproduction

<!-- correct link with fragment -->
<a routerLink="/abc" fragment="myFragment">link 1 with fragment</a>

<!-- bug with empty fragment -->
<a routerLink="/def" fragment="">link 2 with blank fragment</a>

https://stackblitz.com/edit/angular-puzmfb?file=src%2Fapp%2Fapp.component.html

image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions