javascript - Angular View automatically redirecting to default (otherwise) view -
my view automatically redirecting default (otherwise) view , have no idea why. when click, goes view1 view2 , automatically redirects default view3. checked putting console.log()
in view2
view1 -> view2 -> view3
myapp.config(function ($stateprovider, $urlrouterprovider) { $stateprovider .state('view1', { url: "/view1", templateurl: "app/views/start/view1.html", controller: 'mycontroller' }) .state('view2', { url: "/view2/:details", templateurl: "app/views/start/view2.html", controller: 'mycontroller' }); $urlrouterprovider.otherwise('/view3'); });
and calling $state.go
this.
$state.go('view2', { details: json.stringify(response.details) });
i tried intercept preventing default on $statechangestart
ran error :
$digest() iterations reached. aborting
which due interaction issue between $urlrouterprovider
, $stateprovider
explained here. if intercept successfully, not sure if that's correct way. causing it? or how can find out what's causing redirect. way have checked $statechangeerror
, there none.
myapp.controller('mycontroller', ['$scope', '$stateparams', '$state', function ($scope, $stateparams, $state) { $scope.$on('$statechangestart', function (event, tostate, toparams, fromstate, fromparams) { if (tostate.name == "view3" && fromstate.name == "view2") { event.preventdefault(); } }); });
i think response.details has non-url encoded characters making route provider think navigating deeper page i.e. var response = {details:'bar/foo'};
in effect navigating /view2/bar/foo
triggering otherwise.
Comments
Post a Comment