# Ionic 5 Events pass data while switching page

**URL:** <https://forum.ionicframework.com/t/ionic-5-events-pass-data-while-switching-page/210136>\
**Category:** Ionic Angular\
**Created:** [May 26, 2021, 3:36pm UTC](https://forum.ionicframework.com/t/ionic-5-events-pass-data-while-switching-page/210136 "2021-05-26T15:36:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![m1l05z](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/m1l05z/32/137491_2.png) [@m1l05z](https://forum.ionicframework.com/u/m1l05z)\
**Post date:** [May 26, 2021, 3:36pm UTC](https://forum.ionicframework.com/t/ionic-5-events-pass-data-while-switching-page/210136/1 "2021-05-26T15:36:42Z")

</div>

Yo devs,  
I’m struggle with passing some data through [Events](https://medium.com/wizpanda/dealing-with-breaking-change-in-ionic-5-db3ba711dfcd) while transition from one page to another:

```auto
export class Page1 implements OnInit {
  constructor(
    public events: EventsService
  ) {
    events.subscribe('appointment:test', (data: any) => {
        console.log(data)
    });
  }

```

☝ Of course I tried to put subscription inside `ngOnInit` and `ionViewDidEnter`

```auto
export class Page2 implements OnInit {
  constructor(
    public events: EventsService
  ) {}

  goBack() {
    let data = { test: 'test' }
    this.events.publish('appointment:test', data);
    this.navCtrl.navigateBack('page1');
  }

```

☝ Here I also tried to put publishing in `ionViewDidLeave`

I know that I can pass data through navigation but that way worked in previous Ionic version, would be nice to know why it not works anymore 🙂

Also I’m sure that Events are working, when I publish while being on the same page works perfectly fine…

Thanks for any suggestion 🙇‍♂️

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [May 26, 2021, 7:01pm UTC](https://forum.ionicframework.com/t/ionic-5-events-pass-data-while-switching-page/210136/2 "2021-05-26T19:01:52Z")

</div>

While you wait for better answers, I’d like to hear more about what you’re actually trying to do, because whatever it is, I bet there’s a categorically better way of going about it than `Event`s.

---

<div class="post-metadata">

**Author:** ![argCedric](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/argcedric/32/126341_2.png) [@argCedric](https://forum.ionicframework.com/u/argCedric)\
**Post date:** [June 1, 2021, 9:43am UTC](https://forum.ionicframework.com/t/ionic-5-events-pass-data-while-switching-page/210136/3 "2021-06-01T09:43:05Z")

</div>

Hi, since angular 7+ and ionic 4, It seems to me that Event is not recommended.  
To navigate between page use Router from Angular routing  
Are you try this ?

> **[How to Pass Data with Angular Router in Ionic \[v4\]](https://ionicacademy.com/pass-data-angular-router-ionic-4/)**
>
> When you are migrating your Ionic 3 app to Ionic 4 one of the biggest problems you will face is converting your logic to the
