angular - 带有锚标记(划分)刷新的角度 URL 转到主页
问题描述
我在 Angular 应用程序中实现了可访问性合规性,它工作正常,但是我在 url “ http://localhost:4200/#/getdata/bulkdata#main-content ”中遇到了一个小问题,我添加了带有 div 的锚标记id(我页面的主要内容),到目前为止它工作正常,但任何 Ctrl+R 或刷新 url 都会进入主页。
我正在使用角度和打字稿。
非常感谢任何帮助。
请参阅下面的代码以获取 html 文件
<a href="#main-content" class="skip">Skip to main content</a>
下面是 .ts 文件的代码
ngOnInit() {
$(".skip").click(function(event){
$('html,body').animate({
scrollTop: $(window).scrollTop() + 150
});
this.href = " ";
$('#skipfooter').removeAttr('tabindex');
if(window.location.href.indexOf('login') >=0){
this.href=window.location.href + "#main-Content-login";
}
else if (window.location.href.indexOf('#main-content') == -1){
(this.href=window.location.href + "#main-content");
}
else {this.href=window.location.href;
}
var skipTo="#"+this.href.split('#')[2];
// Setting 'tabindex' to -1 takes an element out of normal,tab flow but allows it to be focused via javascript
$(skipTo).attr('tabindex', -1).on('blur focusout', function () {
// when focus leaves this element, remove the tabindex attribute
$(this).removeAttr('tabindex');
}).focus(); // focus on the content container
});
}
}
解决方案
推荐阅读
- android-studio - 动画选择器导致视图初始化崩溃
- python - 如何在没有循环的情况下找到给定经度和纬度的两点之间的距离?
- javascript - Chart.js 如何格式化属于特定轴的数据集(我有两个 yAxes)
- android - 我的底部导航栏只有在我双击切换片段时才有效
- javascript - 单击另一个页面并在另一个页面上打开特定选项卡时如何打开特定选项卡
- angular - 在 Angular 中如何添加
- 将组件 A 中的项目添加到组件 B 中的收藏夹列表中?
- bash - 获取最后一次提交的 git 提交哈希,该哈希影响了 .gitignore-like 文件中未列出的文件
- python - 在没有 Gui 的 centos 上使用 chrome 驱动程序运行 selenium
- excel - 打开IE,在网页搜索栏中搜索值,等待下一页加载
- c# - 通用比较功能