简体   繁体   English

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

[英]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.我需要知道如何从 url 中删除 hash 并在浏览器中更新 url。

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


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

Current behavior:当前行为:

Url in browser: /something Url 在浏览器中:/某事

User clicks: <a [routerLink]="['/home']" fragment="home" >Home</a>用户点击次数: <a [routerLink]="['/home']" fragment="home" >Home</a>

Browser navigates to: /home浏览器导航到:/home

Url in browser: /home#home Url 在浏览器中:/home#home

Page scrolls to: #home页面滚动到:#home

Behavior when using answer to question cited above:使用上述问题的答案时的行为:

Url in browser: /something Url 在浏览器中:/某事

User clicks: <a [routerLink]="['/home']" fragment="home" skipLocationChange>Home</a>用户点击次数: <a [routerLink]="['/home']" fragment="home" skipLocationChange>Home</a>

Browser navigates to: /home浏览器导航到:/home

Url in browser: /something Url 在浏览器中:/某事

Page scrolls to: #home页面滚动到:#home

Desired behavior:期望的行为:

Url in browser: /something Url 在浏览器中:/某事

User clicks: <a [routerLink]="['/home']" fragment="home" >Home</a>用户点击次数: <a [routerLink]="['/home']" fragment="home" >Home</a>

Browser navigates to: /home浏览器导航到:/home

Url in browser: /home // desired behavior is that current url is shown in browser without hash. Url in browser: /home // 期望的行为是当前 url 在没有 hash 的浏览器中显示。

Page scrolls to: #home页面滚动到:#home

https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question 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.为了节省您和我们的时间,我们将系统地关闭所有请求一般支持的问题,并将人们重定向到 Stack Overflow。

The answer to this question is: Don't use unsupported frameworks.这个问题的答案是:不要使用不受支持的框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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