Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs – 如果我的url包含路由参数,则哈希链接重新路由为角大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我有一个级别的路由,则哈希链接按预期工作,没有重新路由.但是我有一些url是country / kh,如果我尝试使用哈希标签,如country / kh#项目,页面重新路由,这是非常讨厌的.

所以,如果im在页面国家,并点击链接#developing,那么页面将滚动到#developing而不重新路由,这是所需的.如果我在页面国家/地区,我点击#projects,页面将重新路由,然后滚动到#projects;我不想要重新路由发生.

这个问题只发生在大自然page1 / parameter#anchor的链接上,而不是简单的pageA#anchor.

@H_673_6@
没有任何代码示例或堆栈空间,很难回答您的问题.我实施了一个密码( http://plnkr.co/edit/oflB21?p=preview)来尝试重现这个问题,但是你可以看到我无法重现这个问题.即您可以轻松地在页面的两个不同部分之间来回浏览,例如#/ Country / Italy#Section-4和#/ Country / Italy#Section-1之间,没有任何页面加载或重新路由.请查看我的工作示例在以下的广告.这很可能是由于一个丢失的哈希爆炸或正斜杠或这样的细节而发生的.

主页的HTML代码段:

<ul>
    <li><a href="#/Country">Go to /Country</a></li>
    <li><a href="#/Country/US">Go to /Country/US</a></li>
    <li><a href="#/Country/Italy#Section-4">Go to /Country/Italy#Section-4</a></li>
    <li><a href="#/Country/Canada#Section-8">Go to /Country/Canada#Section-8</a></li>
</ul>

国家/地区页面HTML代码段:

<div id="Section-1" class="section pink">
    Section 1
    <div ng-if="country">
        <a ng-href="#/Country/{{Country}}#Section-8">Go to /Country/{{Country}}#Section-8</a>
    </div>
    <div ng-if="!country">
        <a ng-href="#/Country#Section-8">Go to /Country#Section-8</a>
    </div>
</div>

所有JavaScript代码

var app = angular.module("app",["ngRoute"]);

app.config(["$routeProvider","$LOCATIOnProvider",function ($routeProvider,$LOCATIOnProvider) {
    $routeProvider
    .when("/",{
        templateUrl: "./home-page.html",caseInsensitiveMatch: true,})
    .when("/Home",})
    .when("/Country",{
        templateUrl: "./country-page.html",})
    .when("/Country/:country",})
}]);

countryController.$inject = ["$scope","$routeParams","$LOCATIOn","$anchorScroll"];
function countryController($scope,$routeParams,$LOCATIOn,$anchorScroll) {

    $scope.country = $routeParams.country;

    if (!!$LOCATIOn.$$hash) {
        $LOCATIOn.hash($LOCATIOn.$$hash);
        $anchorScroll();
    }
}

大佬总结

以上是大佬教程为你收集整理的angularjs – 如果我的url包含路由参数,则哈希链接重新路由为角全部内容,希望文章能够帮你解决angularjs – 如果我的url包含路由参数,则哈希链接重新路由为角所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。