如何在 ui-router 1.0.0 onBefore 中获得 url 'from' 和 'to'?
How I can get url 'from' and 'to' in ui-router 1.0.0 onBefore?
正如标题所说 - 有没有办法从这里获取 url from 和 to:
$transitions.onBefore({}, function(t){
//here
});
有一个working plunker。
使用 UI-Router 我们确实可以访问 from 和 to 状态及其 params 。然后我们可以轻松地将这些信息与 stateService
一起使用,并调用 href()
来回 url parts
这可能是这样的:
$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
正如标题所说 - 有没有办法从这里获取 url from 和 to:
$transitions.onBefore({}, function(t){
//here
});
有一个working plunker。
使用 UI-Router 我们确实可以访问 from 和 to 状态及其 params 。然后我们可以轻松地将这些信息与 stateService
一起使用,并调用 href()
来回 url parts
这可能是这样的:
$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