Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

How can keep url parameters for state, after page refresh?

I have this state

   .state('App.State', {
        abstract: true,
        url: '/App/:param',
        templateUrl: '/page.html',
        controller: 'pageCtrl',
        params: {
            'param': null,
        },

    })

I go to this state with this command

<a ui-sref="App.State({param: paramName})">{{paramName}}</a>

I go to the state, with the params that i want, but when i refresh page (f5) i loose the params, how can keep them after page refresh?

share|improve this question

There is a plunker which does remove abstract: true from your code:

.state('App', {
      template: '<div ui-view ></div>',
})
.state('App.State', {
      //abstract: true,
      url: '/App/:param',
      templateUrl: 'page.html',
      controller: 'pageCtrl',
      params: {
        'param': null,
      },
    })

And then we can use any kind of url (even F5 later) to get to that state

In case, we want to keep that state abstract - we cannot navigate to it. We need its child. There is other plunker

.state('App', {
      template: '<div ui-view ></div>',
})
.state('App.State', {
      //abstract: true,
      url: '/App/:param',
      templateUrl: 'page.html',
      controller: 'pageCtrl',
      params: {
        'param': null,
      },
})
.state('App.State.Child', {
      url: "/",
      template: '<h4> App.State.Child </h4>',
})

The ui-sref cannot be

<a ui-sref="App.State({param: 'xxx'})">
  -- not working while abstract

we have to go to child

<a ui-sref="App.State.Child({param: 'yyy'})">

And these will work then

share|improve this answer
    
Will the second approach(keep abstract state) work for multiple params, i.e. params object has two keys but only one is displayed in the route? link – Shoaib Khan yesterday
    
The point is.. url is the only part - which will survive the refresh (or sending the url and opening it later) The answer is NO. Only url stuff will survive. Hope it helps a bit ;) enjoy UI-Router – Radim Köhler yesterday
    
please take a look at this question. Can you please suggest a better way to achieve the same? – Shoaib Khan yesterday

To maintain the values you should add the parameters in the url like this:

url: '/App/:param'

And remove the params property.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.