正如标题所说 - 有什么方法可以从这里获取 from 和 to 的 url:
$transitions.onBefore({}, function(t){
//here
});
最佳答案
有一个working plunker .
通过 UI-Router,我们确实可以访问 from 和 to 状态及其参数。然后,我们可以轻松地将这些信息与 stateService
一起使用,并调用 href()
来获取和访问 url 部分
这可能是这样的:
$transitions.onBefore({}, function(t){
// to state is TargetState
var toState = t.to();
var toStateName = toState.name;
var toStateParams = t.params(); // by default "to"
var fromState = t.from()
var fromStateName = fromState.name;
var fromStateParams = t.params("from");
// here we generate the HREF
var fromHref = t.router.stateService.href(fromStateName, fromStateParams);
var toHref = t.router.stateService.href( toStateName, toStateParams);
console.log(fromHref);
console.log( toHref);
});
实际检查 here
关于angularjs - 如何在 ui-router 1.0.0 onBefore 中获取 url 'from' 和 'to'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39974922/