繁体   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

这个问题和这个问题不一样。

我需要知道如何从 url 中删除 hash 并在浏览器中更新 url。

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


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

当前行为:

Url 在浏览器中:/某事

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

浏览器导航到:/home

Url 在浏览器中:/home#home

页面滚动到:#home

使用上述问题的答案时的行为:

Url 在浏览器中:/某事

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

浏览器导航到:/home

Url 在浏览器中:/某事

页面滚动到:#home

期望的行为:

Url 在浏览器中:/某事

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

浏览器导航到:/home

Url in browser: /home // 期望的行为是当前 url 在没有 hash 的浏览器中显示。

页面滚动到:#home

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

为了节省您和我们的时间,我们将系统地关闭所有请求一般支持的问题,并将人们重定向到 Stack Overflow。

这个问题的答案是:不要使用不受支持的框架。

暂无
暂无

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

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