我正在使用angular-ui-router 1.0.3
而我正在尝试实施此网址http://localhost:8888/details/2020?pending=true
,但是当我在浏览器中输入该网址并在网页加载时点击enter
,自动将网址更改为此http://localhost:8888/app/details/%7BParam:orderid%20%7BParamType:path%7D%20squash:%20'false'%20optional:%20false%7D?pending=%7BParam:pending%20%5Bobject%20Object%5D%20squash:%20%27false%27%20optional:%20true%7D
这是我的app.config()代码
$stateProvider.state('details',{
url:'/details/:orderid?pending',
name:'details',
templateUrl:'/views/details.html',
resolve:{
load:function($q, $rootScope){
var dfrd = $q.defer();
require(['/js/details.js'],function(){
dfrd.resolve();
$rootScope.$apply();
})
return dfrd.promise;
}
}
})
如果我使用来自其他视图的$state.go({details:2020,pending:true})
作品完美无缺。当我在URL中按Enter键时出现问题
此外,我在控制台中收到此错误:
angular-ui-router.min.js:sourcemap:13 Transition Rejection($ id:0 type:2,message:转换已被不同的取代 过渡,细节:过渡#1('' {} - > '详细信息' {" orderid":" {Param:orderid {ParamType:path} squash:' false' 可选:false}"}))
答案 0 :(得分:0)
[解决] 在我的app.run()中,我有:
$transitions.onBefore({},function(event) {
var target = event._targetState._definition;
$rootScope.toState = target.name
$rootScope.toParams = target.params
if(target.name == 'signin') return true;
return auth.signin();
});
但所有问题都是在$rootScope
事件中使用onBefore
。因此,我的实施的最终代码是:(请注意缺少$rootScope
):
$transitions.onBefore({},function(event) {
var target = event._targetState._definition;
if(target.name == 'signin') return true;
return auth.signin({toState:target.name,toParams:target.params});
});
这段代码没有变化:
$stateProvider.state('details',{
url:'/details/:orderid?pending',
name:'details',
templateUrl:'/views/details.html',
resolve:{
load:function($q, $rootScope){
var dfrd = $q.defer();
require(['/js/details.js'],function(){
dfrd.resolve();
$rootScope.$apply();
})
return dfrd.promise;
}
}
})