最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to go back in Ionic 4 - Stack Overflow

programmeradmin4浏览0评论

I want to add a back button in Ionic4(Angular 7). But I can't find the proper method in Angular Router.

import {Router} from '@angular/router';

How do we go back when clicking a button, in the ponent handler? I'd like to implement it using '@angular/router' not '@angular/mon' => Location

I want to add a back button in Ionic4(Angular 7). But I can't find the proper method in Angular Router.

import {Router} from '@angular/router';

How do we go back when clicking a button, in the ponent handler? I'd like to implement it using '@angular/router' not '@angular/mon' => Location

Share Improve this question edited Dec 5, 2019 at 8:19 Peter Haddad 80.9k25 gold badges145 silver badges146 bronze badges asked Apr 10, 2019 at 14:45 ValeriValeri 1,1425 gold badges15 silver badges32 bronze badges 3
  • stackoverflow./questions/35446955/how-to-go-back-last-page – nircraft Commented Apr 10, 2019 at 14:46
  • Possible duplicate of Angular 5 - Which should I use to navigate backward - href or location.back()? – nircraft Commented Apr 10, 2019 at 14:46
  • I want to go back without using Location, just with @angular/router. – Valeri Commented Apr 10, 2019 at 14:48
Add a ment  | 

3 Answers 3

Reset to default 7

Since you are using ionic 4 then to go backward, you can do the following:

constructor(private navCtrl: NavController) {}

btnClick(){
this.navCtrl.navigateBack('/home'); 
} 

With Angular routing you could use the Location API:

constructor(private location: Location){}

and then when you need to navigate back call:

this.location.back();

Keep in mind that for Angular 7 you have to import Location from @angular/mon

Just do the following if you wanna go back to your previous route.

constructor(private navCtrl: NavController) {}

goBack(){
 this.navCtrl.pop(); 
} 

This'll pop the current page from the navigation stack and return you to the previous page and the part of the page from where you had navigated forward.

发布评论

评论列表(0)

  1. 暂无评论