Usando il routing Angular2, come posso navigare verso una rotta, mentre ho il pushState
tornare alla radice?
Ho esaminato il router.navigate([...])
metodo di Router
, ma non lo trovò lì.
Ad esempio, in Dart "s route_hierarchical
Router
, Potrei farerouter.go("login",{},replace: true,startingFrom:router.root);
risposte:
0 per risposta № 1Fino a quando Angular2 non fornisce questa funzionalità nel suo router, ecco una soluzione temporanea:
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;
}
}
Quindi posso usarlo in questo modo:
await Hist.goBackToRoot();
router.navigate(["/Main",{}]);