javascript - How can I force URL params to appear in URL in ui-router? -
i have simple users.list state, configured this:
$stateprovider.state('users.list', { url: '/users/list?type', reloadonsearch: false, templateurl: 'templates/users/list.html', params: { type: { value: 'all' }, }, }); i'm trying force type param appear in url. when click on link generated ui-sref directive, works great. problem happens when access /users/list directly in browser. although param correctly configured $state.params, not appear in url.
usually that's not big problem, becomes 1 when need use seasonal params. instance, imagine that, default, want list new users, registered past week until now. setting param from default value of today - 7 days, different every day.
so, when user shares url without param someone, can cause lot of trouble, like: "hey, delete third 1 top me, it's cheating.". if person receives message decides open url in day, list different, , can see i'm worried about.
i couldn't find me, i'm asking here. have done that? feasible?
there a working plunker
we have use setting squash:
.state('users.list', { url: '/users/list?type', reloadonsearch: false, templateurl: 'templates/users/list.html', params: { type: { value: 'all', squash: false, }, }, }); check here
for more details observe these:
- angular ui router passing data between states without url
- how pass parameters using ui-sref in ui-router controller
- with defaulted parameters how rewrite url?
extend (updated working plunker)
in case, want initial page using defaults, can use .otherwise() setting:
//$urlrouterprovider.otherwise('/users/list'); $urlrouterprovider.otherwise(function($injector, $location) { var state = $injector.get('$state'); state.go('users.list'); return $location.path(); }); check that in action here , read more details here:
Comments
Post a Comment