Sunday, September 22, 2019

angularjs - How to add state params in #stateprovider in UI-router without showing it in URL




I want to maintain state of user-data. So that even on reload I can show the exact result to user using stateParams but without showing in URL(query string) in browser. How can I achieve this?



Answer



var app = angular.module('rootApp', [
'ui.router'
]);

pp.config(function ($stateProvider, $urlRouterProvider, $locationProvider, $httpProvider) {
$urlRouterProvider.otherwise('/signin');
$stateProvider
.state('user', {
url: '/home',

params: {
guid: null,
role: NaN
},
templateUrl: 'Components/default/home.html',
controller: 'rootCtrl',
data: {
requireLogin: true
}
})


});


now you can navigate to this state from href tag like:






or by method :




$state.go('user', {param: {guid: 1, role: 'anyrole'}});

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...