简体   繁体   中英

How to remove hash from url in Angular 9 and also update the url in the browser to the current url

This question is not the same as this one .

I need to know how to remove the hash from from the url and also update the url in the browser.

@NgModule({
  imports: [RouterModule.forRoot(routes, { anchorScrolling: 'enabled', useHash: false, scrollPositionRestoration:'enabled' })],


"@angular/router": "~9.1.2",

Current behavior:

Url in browser: /something

User clicks: <a [routerLink]="['/home']" fragment="home" >Home</a>

Browser navigates to: /home

Url in browser: /home#home

Page scrolls to: #home

Behavior when using answer to question cited above:

Url in browser: /something

User clicks: <a [routerLink]="['/home']" fragment="home" skipLocationChange>Home</a>

Browser navigates to: /home

Url in browser: /something

Page scrolls to: #home

Desired behavior:

Url in browser: /something

User clicks: <a [routerLink]="['/home']" fragment="home" >Home</a>

Browser navigates to: /home

Url in browser: /home // desired behavior is that current url is shown in browser without hash.

Page scrolls to: #home

https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

To save your and our time, we will systematically close all issues that are requests for general support and redirect people to Stack Overflow.

The answer to this question is: Don't use unsupported frameworks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM