简体   繁体   中英

AngularJs Url changes but old view is loaded using ui-router

I am using ui-router and I have a setup like this

In app.js I have the following

 $stateProvider
      .state('TechReadiness', {
          url: "/Dashboard/TechReadiness",
          templateUrl: "/partials/TechnicalReadinessReport.aspx"
      })
    .state('TechReadiness.details', {
        url: "/ReadinessDetails/:a/:b",
        templateUrl: function ($stateParams) {
            return "/partials/TechReadinessDetails.aspx?b=" + $stateParams.b + '&a=' + $stateParams.a;
        }
    })

There is a page and on that page I am creating the links as shown below

$("#Chart5ImageMap area").each(function () {
                var vHref = $(this).attr('href');
                var arg1 = vHref.substring(vHref.indexOf("'") + 1, vHref.indexOf(",") - 1);
                var arg2 = vHref.substring(vHref.indexOf(",") + 2, vHref.lastIndexOf("'"));
                var a = arg2.split(',');
                $(this).attr('href', '#/Dashboard/TechReadiness/ReadinessDetails/' + a[0] +'/'+a[1]);
            });

This changes all the click postback events(asp.net Chart Control) to simple links. Now the problem is that whenever I click the link the url gets updated correctly but the corresponding view doesn't get loaded.

for example: If I click the link with a=parameter1,b=parameter2

url becomes http://localhost:63893/#/Dashboard/TechReadiness/ReadinessDetails/parameter1/parameter2

accordingly and the correct view is loaded

but on when I click links with

a=parameter2,b=parameter2

the url changes to http://localhost:63893/#/Dashboard/TechReadiness/ReadinessDetails/parameter2/parameter2

but the content in the view doenst change

When you already in the state "TechReadiness.details", the view templateUrl will not reload . You should set the parametes to the controller but view template.

The problem was that I was using ASP.Net and thus there was client side caching enabled on the pages because of the following line on top of pages

<%@ OutputCache Duration="10" Location="Server" VaryByParam="none" %>

and I fixed it by replacing the above by

<%@ OutputCache Duration="10" Location="Server" VaryByParam="a;b" %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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