javascript - URL Route Parameters in AngularJS ui-router -


i want able reload nested view of application , attached route parameter on can have url routing in application. cannot figure out how this, had working query this:

$location.search('userid', user._id); //http://localhost:9000/#/user/?userid=123456789 

my desired url below, userid = 123456789

http://localhost:9000/#/user/123456789 

my app.js file

$stateprovider     .state('index', {         url: '/',         views: {             '@' : {                 templateurl: 'views/layout.html'             },             'top@index' : {                 templateurl: 'views/top.html',                 controller: function($scope, $state) {                     $scope.userlogout = function() {                         $state.go('login');                     };                 }             },             'left@index' : { templateurl: 'views/left.html' },             'main@index' : { templateurl: 'views/main.html' }         }     })     .state('index.user', {         url: 'user:userid',         templateurl: 'views/user/user.html',         controller: 'userctrl'     })     .state('index.user.detail', {         url: '/',         views: {             'detail@index' : {                 templateurl: 'views/user/details.html',                 controller: 'detailctrl'             }         }     }) 

in controller:

$state.reload('index.user.detail', {userid: $scope.user._id}); 

as using ui-router can use $state.go('index.user', { userid: {{yourid}} });

to allow query string parameter work using ui-router write state this,

.state('index.user', {     url: 'user/?userid=:param',     templateurl: 'views/user/user.html',     controller: 'userctrl' }) 

that allow work,

//http://localhost:9000/#/user/?userid=123456789

without query string parameter (your desired url) this,

.state('index.user', {     url: 'user/:userid',     templateurl: 'views/user/user.html',     controller: 'userctrl' }) 

http://localhost:9000/#/user/123456789


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -