0
我希望能夠重新加載我的應用程序的嵌套視圖並附加一個路由參數,以便我的應用程序中可以有URL路由。我無法弄清楚如何做到這一點,我最初有它的查詢工作是這樣的:AngularJS中的URL路由參數ui-router
$location.search('userId', user._id);
//http://localhost:9000/#/user/?userId=123456789
我想要的網址是下面,用userId = 123456789
http://localhost:9000/#/user/123456789
我app.js文件
$stateProvider
.state('index', {
url: '/',
views: {
'@' : {
templateUrl: 'views/layout.html'
},
'[email protected]' : {
templateUrl: 'views/top.html',
controller: function($scope, $state) {
$scope.userLogOut = function() {
$state.go('login');
};
}
},
'[email protected]' : { templateUrl: 'views/left.html' },
'[email protected]' : { templateUrl: 'views/main.html' }
}
})
.state('index.user', {
url: 'user:userId',
templateUrl: 'views/user/user.html',
controller: 'UserCtrl'
})
.state('index.user.detail', {
url: '/',
views: {
'[email protected]' : {
templateUrl: 'views/user/details.html',
controller: 'DetailCtrl'
}
}
})
在我的控制器:
$state.reload('index.user.detail', {userId: $scope.user._id});
'$ state.go( 'index.user',{用戶名:{{yourid}}} );'不會加載'.detail'的嵌套狀態。然後,如果我嘗試'$ state.go('index.user.detail',{userId:{{yourid}}});'我不重新加載視圖,因爲角度認爲我已經在我想要的視圖。我無法添加'{reload:true}',因爲它只是在循環中重新加載。我希望能夠設置URL並重新載入'.details'視圖 – tester123