简体   繁体   English

Angular 2+ (v11) 自动将 URL 中的片段 hash (#) 编码为 %23

[英]Angular 2+ (v11) automatically encode fragment hash (#) in URL into %23

My Angular app has to automatically scroll (only Y-axis) to a certain component when a corresponding hash exists in the URL.当 URL 中存在相应的 hash 时,我的 Angular 应用程序必须自动滚动(仅 Y 轴)到某个组件。

Eg url.com/page1#element1 should make the browser automatically scrolls to Element 1, naturally with #element1 inside the HTML tag.例如url.com/page1#element1应该使浏览器自动滚动到元素 1,自然而然地在 HTML 标签内使用#element1

But somehow my Angular app automatically replaces the hash (#) with %23, its URL-encoded version.但不知何故,我的 Angular 应用程序自动将 hash (#) 替换为 %23,它的 URL 编码版本。 This causes the problem that my app cannot recognise any fragment in the URL (I use this.activatedRoute.fragment.subscribe() to get the fragment value) I tried checking everywhere in the code, but I can't seem to find the source of the problem.这导致我的应用程序无法识别 URL 中的任何片段的问题(我使用this.activatedRoute.fragment.subscribe()来获取片段值)我尝试在代码中到处检查,但似乎找不到源的问题。 Does anybody have any possible solution to this?有人对此有任何可能的解决方案吗? Thank you!谢谢!

Not really a fix, but I think this is a problem specific to my app.不是真正的修复,但我认为这是我的应用程序特有的问题。 So I basically have 2 mode of my app, one is the normal ng serve and the other one is SSR mode (server side rendering).所以我的应用程序基本上有 2 种模式,一种是普通的ng serve ,另一种是 SSR 模式(服务器端渲染)。 Basically this problem only shows up in the normal mode, but if I run the app with the SSR mode (also what I have in prod), the hash is being kept as-is.基本上这个问题只出现在正常模式下,但如果我以 SSR 模式运行应用程序(也是我在产品中所拥有的),hash 将保持原样。

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

相关问题 angular v11 + Scss 编译失败 - angular v11 + Scss failed to compile Angular V11:NullInjectorError:没有 ControlContainer 的提供程序 - Angular V11: NullInjectorError: No provider for ControlContainer Angular v8 到 v11 - 禁用常春藤的 entryComponents 问题 - Angular v8 to v11 - entryComponents issue with Ivy disabled 在架构中找不到“tsconfig”-将 tslint 迁移到 eslint (Angular v11) - 'tsConfig' is not found in schema - Migrating tslint to eslint (Angular v11) 如何测试动态加载组件的 Angular (v11) 组件 - How test an Angular (v11) component that loads components dynamically angular 2+,通过 hash(#) url 滑动到指定元素 - angular 2+, slide to the specified element by hash(#) url 删除 URL Angular 11 中的哈希(#) - Remove hash(#) in URL Angular 11 Angular 自定义材质主题在 v11 到 14 升级后未加载 - Angular Custom Material Theme not loading after v11 to 14 upgrade 如何解决这个错误? angular v11 原理图工作流程失败。 看上面 - How to solve this error ? angular v11 The Schematic workflow failed. See above 在 Angular v11/12 中使用 d3.stack() 实现堆积条形图时出现问题 - Problem implementing Stacked Bar Chart using d3.stack() in Angular v11/12
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM