$state.go('myState',{ redirect : true });
我还需要在事件stateChangeStart中检查该参数.像这样:
$rootScope.$on('$stateChangeStart',function (event,toState,toParams,fromState,fromParams) {
//redirect parameter is not available here.
//should be in toParams right?
}
编辑:这是我的statedeFinition:
$stateProvider.state('customer.search',{
url: '/search',views: {
"right-flyover@": {
templateUrl: 'customer/search/search.tpl.html',controller: 'CustomerSearchCtrl'
}
},data: {
pageTitle: 'Sök användare',hidden: true
}
});
URL Parameters(引用:)
通常,URL具有动态部分,称为参数.有几个选项可用于指定参数.基本参数如下所示:
$stateProvider
.state('contacts.detail',{
url: "/contacts/:contactId",templateUrl: 'contacts.detail.html',controller: function ($stateParams) {
// If we got here from a url of /contacts/42
expect($stateParams).toBe({contactId: 42});
}
})
因此,如果您想使用param重定向,您的状态应如下所示:
$stateProvider.state('customer.search',{
url: '/search/:redirect',...
});
然后我们可以使用:
$state.go('customer.search',{ redirect : true });
这将是$statePrams的一部分
但也许您尝试使用已发送的选项,而不是参数:
> $state.go(to [,toParams] [,options])(引用:)
选项
Object – If Object is passed,object is an options hash. The following options are supported:
> location布尔值或“替换”(默认为true),如果为true将更新位置栏中的URL,如果为false则不会.如果字符串“replace”,将更新url并替换上一个历史记录.
> inherit Boolean(默认为true),如果为true,则从当前url继承url参数.
> relative stateObject(默认$state.$current),当使用相对路径(例如’^’)进行转换时,定义哪个状态是相对的.
> notify Boolean(默认为true),如果为true将广播$stateChangeStart和$stateChangeSuccess事件.
> reload v0.2.5布尔值(默认值为false),则强制转换,即使状态或参数没有改变,也就是重新加载相同的状态.它与reloadOnSearch不同,因为当你想在一切都相同时强制重新加载时你会使用它,包括搜索参数.
那将是第三个参数(重新加载而不是重定向):
$state.go('myState',null,{ reload: true });