user3759883 user3759883 - 3 months ago 57
AngularJS Question

$stateParams getting null after page refresh

When passing $stateParams through $state.go it is getting correctly when i click the link directly, but getting null after page refresh or open through another window.

I have the following function:

$scope.urlvalues = function(url,page) {
var result = {url:url, page:page};
$state.go("detailpage", result);
}


And my state looks like this:

.state('detailpage', {
url: "/page/overview",
templateUrl: "/page_details.html",
controller: "PageDetailsController",
params: {
url: null,
page: null
},
})


Thanks in advance.

Answer

Can you try:

.state('detailpage', {
        url: "/page/overview/:url/:page",
        templateUrl: "/page_details.html",
        controller: "PageDetailsController",

    })

Then, when you go to the page the url will be set and will be there when you refresh.