角历史路线和碎片

发布于 2025-01-21 15:23:00 字数 862 浏览 3 评论 0 原文

我的Angular应用程序使用“历史路由路径”

localhost/blog/acrate/:ID

在OPEN Localhost/blog/actity/123456 上此路由时渲染

降价内容

- [one](#one)
- [two](#two)

# one
some thing

# two
some thing

渲染html

<a herf="#one">one</a>
<a herf="#two">two</a>
<h1 id="one">one</h1>
<p>some thing</p>
<h1 id="two">one</h1>
<p>some thing</p>

,但单击标签重定向到root路径,

单击标签时如何滚动到片段

--------------------------------------------------------------------------------

请参阅此处

my angular app use the history route path

localhost/blog/article/:id

when this route on open localhost/blog/article/123456, httpclient get some markdown content data and render

the markdown content

- [one](#one)
- [two](#two)

# one
some thing

# two
some thing

render html

<a herf="#one">one</a>
<a herf="#two">two</a>
<h1 id="one">one</h1>
<p>some thing</p>
<h1 id="two">one</h1>
<p>some thing</p>

but click the a tag redirect to root path

how to scroll to the fragment when clicking on a tag

---------UPDATE---------

The problem has been solved

refer to here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

街角卖回忆 2025-01-28 15:23:00

您需要在routermotule.forroot()中启用aNchorsCrolling(如下): -

RouterModule.forRoot({anchorScrolling: true})

并使用片段属性分配如上上面的片段而不是HREF。

<a [routerLink]='"."' [fragment]="one">Dashboard</a>

您可以在此处阅读有关它的信息: -

htttps:htttps:// mided。 com/dev-genius/Advanced-router-configuration-in-angular-d22c6dc420be

or: -

You need to enable anchorScrolling in RouterModule.forRoot() like below :-

RouterModule.forRoot({anchorScrolling: true})

And use fragment attribute to assign the fragment like above instead of href.

<a [routerLink]='"."' [fragment]="one">Dashboard</a>

You can read about it here :-

https://medium.com/dev-genius/advanced-router-configuration-in-angular-d22c6dc420be

Or :-

https://angular.io/api/router/ExtraOptions

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文