我正在使用路由段提供程序在angular中进行路由。如何使用$location.path().进行url调用
代码如下:
FinancialGameApp.config(['$routeSegmentProvider', '$routeProvider', function ($routeSegmentProvider, $routeProvider) {
// Configuring provider options
$routeSegmentProvider.options.autoLoadTemplates = true;
// Setting routes. This consists of two parts:
// 1. `when` is similar to vanilla $route `when` but takes segment name instead of params hash
// 2. traversing through segment tree to set it up
$routeSegmentProvider
.when('/Home', 's1')
.when('/Login', 's2')
.when('/Signup', 's3')
.when('/UserDetails', 's4')
.segment('s1', {
templateUrl: 'Views/home.html',
controller: 'loginController'
})
.segment('s2', {
templateUrl: 'Views/login.html',
controller: 'loginController'
})
.segment('s3', {
templateUrl: 'Views/signup.html',
controller: 'loginController'
})
.segment('s4', {
templateUrl: 'Views/UserDetailsPage.html',
controller: 'userDetailsController'
})
$routeProvider.otherwise({ redirectTo: '/Home' });
}]);
我想通过使用$location.path()的方法调用来调用段s4
authService.login($scope.loginData).then(function (response) {
$location.path('/UserDetails');
}
尝试在url之前添加#。
authService.login($scope.loginData).then(function (response) {
$location.path('/#/UserDetails');
}
此外,您可以将段名称与getSegmentUrl
一起使用来获得哈希,而不是直接的url
authService.login($scope.loginData).then(function (response) {
$location.path($routeSegment.getSegmentUrl('s4'));
}