使用Angular2路由,如何在导航到某个路由的同时让pushState
一直弹出回到根目录?
我调查了router.navigate([...])
的Router
方法,但在那里没有找到。
例如,在Dart的route_hierarchical
Router
中,我可以做router.go('login',{},replace: true,startingFrom:router.root);
最佳答案
直到Angular2在路由器中提供此功能之前,这是一个临时解决方法:
abstract class Hist {
static int _initialLength;
// Call this ASAP when app starts.
static void setAsInitialLength() {
_initialLength = window.history.length;
}
static Future goBackToRoot() async {
Completer completer = new Completer();
window.history.go(-(window.history.length-_initialLength));
Timer.run((){
completer.complete();
});
return completer.future;
}
}
然后我可以像这样使用它:
await Hist.goBackToRoot();
router.navigate(['/Main',{}]);
关于dart - Angular2:导航到路由并弹出回到pushState堆栈的根,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35494651/