mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 03:00:58 +08:00
fix(angular): back navigation and back-button play better (#15293)
* fix(angular): use location instead of navigateByUrl Closes #15290 * fix(angular): change router methods
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { Injectable, Optional } from '@angular/core';
|
||||
import { Location } from '@angular/common';
|
||||
import { NavigationExtras, Router, UrlTree } from '@angular/router';
|
||||
|
||||
export const enum NavIntent {
|
||||
@ -16,24 +17,30 @@ export class NavController {
|
||||
private stack: string[] = [];
|
||||
|
||||
constructor(
|
||||
private location: Location,
|
||||
@Optional() private router?: Router
|
||||
) {}
|
||||
|
||||
goForward(url: string | UrlTree, animated?: boolean, extras?: NavigationExtras) {
|
||||
navigateForward(url: string | UrlTree, animated?: boolean, extras?: NavigationExtras) {
|
||||
this.setIntent(NavIntent.Forward, animated);
|
||||
return this.router!.navigateByUrl(url, extras);
|
||||
}
|
||||
|
||||
goBack(url: string | UrlTree, animated?: boolean, extras?: NavigationExtras) {
|
||||
navigateBack(url: string | UrlTree, animated?: boolean, extras?: NavigationExtras) {
|
||||
this.setIntent(NavIntent.Back, animated);
|
||||
return this.router!.navigateByUrl(url, extras);
|
||||
return this.router!.navigateByUrl(url, { replaceUrl: true, ...extras });
|
||||
}
|
||||
|
||||
goRoot(url: string | UrlTree, animated?: boolean, extras?: NavigationExtras) {
|
||||
navigateRoot(url: string | UrlTree, animated?: boolean, extras?: NavigationExtras) {
|
||||
this.setIntent(NavIntent.Root, animated);
|
||||
return this.router!.navigateByUrl(url, extras);
|
||||
}
|
||||
|
||||
goBack(animated?: boolean) {
|
||||
this.setIntent(NavIntent.Back, animated);
|
||||
return this.location.back();
|
||||
}
|
||||
|
||||
setIntent(intent: NavIntent, animated?: boolean) {
|
||||
this.intent = intent;
|
||||
this.animated = (animated === undefined)
|
||||
|
Reference in New Issue
Block a user